【问题标题】:Call function in function event (onChange), from Select created in Leaflet and Vue.js函数事件(onChange)中的调用函数,来自在 Leaflet 和 Vue.js 中创建的 Select
【发布时间】:2019-05-12 18:50:25
【问题描述】:

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

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

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

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

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

我试着放了

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

但无论如何都不起作用。

我该怎么做?谢谢。

【问题讨论】:

    标签: javascript vue.js vuejs2 leaflet vue-component


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-05-27
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多