Accessing props in vue component data function

前端 未结 5 809
醉话见心
醉话见心 2021-02-03 16:59

I am passing a props to a component:





        
5条回答
  •  难免孤独
    2021-02-03 17:09

    Note that this does not work if you are using an arrow function for assigning your data:

    data: () => ({
      somevar: this.messageId // undefined
    }),
    

    Because this will not point to the component. Instead, use a plain function:

    data: function() {
      return { somevar: this.messageId }
    },
    

    or using ES6 object method shorthand as Siva Tumma suggested:

    data() {
        return { somevar: this.messageId }
    }
    

提交回复
热议问题