[Vuejs]-Preferred way to access props in Vue Single File Component

3👍

Component properties as well as passed in props should always be referenced to by this.propName, because you shouldn’t assign a component property with the same name as a passed in prop. In this case Vue will respond with an error.

👤Aer0

0👍

As Aer0 said, they shouldn’t have the same names:

props: ['propMessage'],

data() {
   return {
      message: ''
   };
},

created() {
    console.log(this.propMessage);
    console.log(this.message);
}
👤Rich

Leave a comment