Sometimes, we want to access props in a Vue.js component data function.
In this article, we’ll look at how to access props in a Vue.js component data function.
How to access props in a Vue.js component data function?
To access props in a Vue.js component data function, we can get them from this
.
For instance, we write
<script>
//...
export default {
//...
props: ["messageId"],
data() {
const theData = {
someVar: this.messageId,
};
return theData;
},
//...
};
</script>
to register the messageId
prop.
Then we get the initial value of the messageId
prop with this.messageId
in the data
method.
Conclusion
To access props in a Vue.js component data function, we can get them from this
.