vue父组件调用子组件的事件方法
子组件:foods<div id='app'> <div class="box" v-show="showFlag">11111111111111</div></div><script>export default
·
子组件:foods
<div id='app'>
<div class="box" v-show="showFlag">11111111111111</div>
</div>
<script>
export default({
data(){return{showFlag:false}},
methods:{
show(){
this.showFlag = true
}
}
})
</script>
父组件:parent.vue
<div class="parents">
<Foods ref='foods'></Foods>
<button @click='btn'>我是父组件</button>
</div>
<script>
import Foods from 'foods'
export default {
methods:{
btn(){
this.$refs.foods.show()
}
},
components:{
Foods
}
}
</script>
更多推荐
已为社区贡献1条内容
所有评论(0)