I know this question may be duplicated or asked several times. But I'm so new in Vue and I'm not able to find a clear question. How can I read/write a variable from the app into the components? All I see around they are passing values from the parent component into the child component. This seems like is not working in this case. This is the structure of my app, I would like to keep this structure.
let app = Vue.createApp({
components:['contrib'],
data(){
return{
contButton:"first value",
}
},
methods: {
someMethods:{
},
},
})
app.component('contrib',{
props:['contButton'],
template: `
<div>
<button class="button is-small" id="myBtn" @click="showCont">{{contButton}}</button>
</div>
`,
data(){
return{
newCont:null,
}
},
methods:{
showCont() {
this.newCont=this.contButton
console.log(this.newCont)
},
}
})
app.mount('#app')