methods: {
A: function() {
setInterval(function(){
this.B();
},500)
},
B: function() {
console.log('func B')
}
}
這樣寫會報錯,要怎麼達到這樣的效果呢?
淡淡烟草味2017-05-19 10:33:53
可以使用箭頭函數
methods: {
A: function() {
setInterval(() => {
this.B();
}, 500)
},
B: function() {
console.log('func B')
}
}
或
methods: {
A: function() {
setInterval(this.B, 500)
},
B: function() {
console.log('func B')
}
}