npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-formula-editor

v0.2.3

Published

低代码公式编辑器,支持动态计算

Downloads

101

Readme

vue-formula-editor

⚠️ 注意:目前仅支持 Vue2

安装

$ npm i vue-formula-editor -S

example地址

在线体验

demo & 源码

使用方式

import { calculate, formulaWatcher, FormulaEditor } from 'vue-formula-editor'

主要导出三个对象

  • calculate计算结果函数
  • formulaWatcher自动监听表单变化计算结果
  • FormulaEditor组件

FormulaEditor组件 Props 参数说明

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ----------- | --------------------- | ------ | ------ | ------ | | fieldList | 表单字段 | Array | 必填 | - | | formulaList | 公式函数列表 | Array | 必填 | - | | formulaConf | 公式编辑配置 / 回显值 | Object | 必填 | - |

fieldList 数据格式

[
  {
    fullName: '名称',
    value: 'string',
    enCode: 'name',
  },
]

formulaList 数据格式

[
  {
    name: '常用函数',
    enCode: 'frequentlyUse',
    formula: [
      {
        name: 'SUM',
        enCode: 'SUM',
        tip: '求和',
        example: 'SUM(数学成绩,语文成绩,英语成绩,...) = 各科总成绩',
        usage: 'SUM(数值1,数值2,...)。',
      },
    ],
  },
]

formulaConf 数据格式

其中 marks 为可选参数,因为不一定有变量参与计算

{
    "text": "CONCATENATE(名称,描述)",
    "marks": [{
            "from": {
                "line": 0,
                "ch": 12
            },
            "to": {
                "line": 0,
                "ch": 14
            },
            "enCode": "name"
        },
        {
            "from": {
                "line": 0,
                "ch": 15,
                "sticky": null
            },
            "to": {
                "line": 0,
                "ch": 17,
                "sticky": null
            },
            "enCode": "desc"
        }
    ]
}

FormulaEditor组件 Methods 方法说明

| 方法名 | 说明 | 参数 | | ------- | ---------------- | ---- | | getData | 获取公式编辑配置 | 无 | | reset | 重置公式编辑器 | 无 |

自动监听数据变化 - formulaWatcher

自动监听数据变化,并实时计算结果

formulaWatcher Params 参数说明

| 参数 | 说明 | | ----------- | ----------------------------------------------------------- | | vm | 当前 Vue 实例 | | formData | 计算公式所需的数据; key:监听的名称、value:监听的表单数据 | | formulaConf | 计算公式配置 | | fn | 回调函数 |

使用示例

/**
 * 动态监听并返回计算结果
 * @param {VueContentInstance} vm 当前Vue实例
 * @param {Object} formData 计算公式所需的数据
 * @param {Object} formulaConf 计算公式配置
 * @param {Function} fn 回调函数
 * @returns {Function} 取消监听函数
 */
this.watchData = formulaWatcher(
  this,
  { key: 'formData', value: this.formData },
  this.formulaConf,
  data => {
    this.result = data
  }
)

计算结果方法 - calculate

/**
 * 计算公式结果
 * @param {Object} formulaConf 计算公式配置 
 */
this.result = calculate({
  text: 'SUM(1,2,3,4,5,6,7,8,9,10)',
})