0

We are using Vue and arrow function on methods. Since arrow function has no this keyword, how can we access the data like list or object

export default {
  data() {
    return {
      list: [],
      object: {},
    }
  },
  methods: {
    onSubmit: (e) => {
      //How can access this here?
      //Im trying to access this.list
      console.log(this);
    }
  },
}

Thanks in advance.

Miro
  • 225
  • 2
  • 10

1 Answers1

0

It's not recommended that you use arrow functions when declaring methods in your Vue components.

Why not just use someting like this?:

methods:{
  onSubmit(e){
   ...
  }
}

You can refer to other articles about to topics to get detailed info, since there are tons of replies on the same topic already:

How to access the correct `this` inside a callback?