問題描述
我正在用 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()
../
但無論如何都不起作用.
But not working, anyway.
我該怎么做?謝謝.
推薦答案
你應該使用箭頭函數 ()=>{...}
來訪問組件實例 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!