問題描述
我正在用 Vue.js 和 Leaflet 制作一個(gè)應(yīng)用程序.在這個(gè)應(yīng)用程序中,我在使用 L.DomUtil 創(chuàng)建的傳單中選擇了一個(gè)
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);
我沒有找到在這個(gè)選擇"中放置v-on:change"的方法,所以,我必須在 Vue.js 的函數(shù)方法中調(diào)用一個(gè)事件函數(shù).
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()
}
}
}
但它不起作用,錯(cuò)誤是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.
我該怎么做?謝謝.
推薦答案
你應(yīng)該使用箭頭函數(shù) ()=>{...}
來訪問組件實(shí)例 this
如下:
You should use arrow function ()=>{...}
to get access to the component instance this
as follows :
secondFunction() {
this.select.on('change', (e)=>{
this.firstFunction()
}
}
這篇關(guān)于函數(shù)事件(onChange)中的調(diào)用函數(shù),來自在 Leaflet 和 Vue.js 中創(chuàng)建的 Select的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!