Answer the question
In order to leave comments, you need to log in
How to change data in vue.js component?
There are two components - a button and a menu that should be opened by this button.
button:
<template>
<button type="button" class="navbar-toggle collapsed" @click="showLeftMenu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</template>
<script type="text/babel">
export default{
methods:{
showLeftMenu(){
this.$root.$emit('show')
}
}
}
</script>
<template>
<div class="sidemenu" v-show="visible">
{{visible}}
</div>
</template>
<script type="text/babel">
export default{
data(){
return{
visible: false
}
},
created: function(){
console.log(this.visible)
},
mounted(){
this.$root.$on('show', function () {
console.log('open!')
this.visible = true;
console.log(this.visible)
})
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question