在js中调用vue的方法

1、在vue的钩子函数中将需要调用的函数赋值给window。

  mounted () {
    
    
    // 将Vue方法传到全局对象window中
    window.createNode = this.createNode
  },
  methods:{
    
    
    /**
     * 动态创建节点
     * @param id 节点id
     * @param x 节点坐标(x轴)
     * @param y 节点坐标(y轴)
     * @param text 节点文本
     */
    createNode (id, x, y, text) {
    
    
      this.lf.addNode({
    
    
        type: 'item',
        x: x,
        y: y,
        id: id,
        text: {
    
    
          value: text,
          x: x,
          y: y
        }
      })
    }
  }

2、在js中直接使用

  <script  type="text/javascript">
      var point= "1";
      var arr =[100,200]
      var name = 'test'
      createNode(point,parseInt(arr[0]),parseInt(arr[1]),name)
  </script>

おすすめ

転載: blog.csdn.net/Java_Fly1/article/details/118573354