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')
}
}