0

This is the first time I'm using VueJs, so this might be a very basic thing, but in one of my callbacks I try to set a new value to a value, saved in the "data" component.

But whenever I try to run this method, Vue says my "this" is undefined, so I can't set this new value.

export default {
    name: 'app',
    data() {
        return {
            collection : {},
        }
    },
    mounted: function(){
        var event = contract.statuschangedEvent(function(error, result) {
        if (!error){
            this.collection[result.args.id].status = result.args.status
        }
    });
    ...

The "contract" object is a web3 object, and the syntax should be fine according to this documentation

The error I'm getting is "Uncaught TypeError: Cannot read property '[object Object]' of undefined"

bertcommeine
  • 5
  • 1
  • 3
  • One of the solution would be bind `this` to the callback, second is arrow syntax function which would bind this automatically to parent context, and last is place `this` reference into the variable, outside the callback scope. @thanksd gave you good reference. – Belmin Bedak Sep 13 '17 at 15:12
  • Thanks, the problem I mentioned was indeed already solved! – bertcommeine Sep 13 '17 at 15:22

0 Answers0