在函数事件 (onChange) 中调用函数,来自在 Leaflet 和 Vue.js 中创建的 Select [英] Call function in function event (onChange), from Select created in Leaflet and Vue.js

查看:39
本文介绍了在函数事件 (onChange) 中调用函数,来自在 Leaflet 和 Vue.js 中创建的 Select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Vue.js 和 Leaflet 制作一个应用程序.在这个应用程序中,我在使用 L.DomUtil 创建的传单中有一个选择

I am making a app in Vue.js and Leaflet. In this app, I have a Select in leaflet created with L.DomUtil

  this.select = L.DomUtil.create('select','leaflet-countryselect',this.div);

我没有找到在这个选择"中放置v-on:change"的方法,所以,我必须在 Vue.js 的函数方法中调用一个事件函数.

I do not find the way for put 'v-on:change' in this 'Select', so, I have to call a event function, inside to a Function Method in Vue.js.

 methods: {
   firstFunction{
   },
   secondFunction() {
      this.select.on('change', function(e){
           this.firstFunction()
      }
   }
 }

但它不起作用,错误是this.firstFunction() is not a function"

But it not working, the error is "this.firstFunction() is not a function"

我试着把

   .../
     var _self = this
     _self.firstFunction()
    ../

但无论如何都行不通.

我该怎么做?谢谢.

推荐答案

你应该使用箭头函数 ()=>{...} 来访问组件实例 this如下:

You should use arrow function ()=>{...} to get access to the component instance this as follows :

      secondFunction() {
          this.select.on('change', (e)=>{
            this.firstFunction()
              }
        }

这篇关于在函数事件 (onChange) 中调用函数,来自在 Leaflet 和 Vue.js 中创建的 Select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆