I have created a basic component, but I am encountering an issue where attempting to access the component's data returns undefined. Here is my code snippet:
Vue.component({
template:`<div>{{message}}</div>`,
data() {
return { comments: [
{title: 'hello' , message: 'world'},
{title: 'hellowww' , message: 'worldssss'},
]}
},
mounted: function() {
console.log(this.comments) // prints undefined - not working
console.log(this.$root.comments) // prints undefined - not working
console.log(comments) // prints undefined - not working
}
});
var app = new Vue({
el: '#root'
});