methods: {
A: function() {
setInterval(function(){
this.B();
},500)
},
B: function() {
console.log('func B')
}
}
Writing like this will report an error. How to achieve such an effect?
淡淡烟草味2017-05-19 10:33:53
You can use arrow functions
methods: {
A: function() {
setInterval(() => {
this.B();
}, 500)
},
B: function() {
console.log('func B')
}
}
or
methods: {
A: function() {
setInterval(this.B, 500)
},
B: function() {
console.log('func B')
}
}
阿神2017-05-19 10:33:53
methods: {
A () {
let that = this;
setInterval(function(){
that.B();
},500)
},
B () {
console.log('func B')
}
}