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?
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') } }
methods: { A () { let that = this; setInterval(function(){ that.B(); },500) }, B () { console.log('func B') } }
You can use arrow functions
or