子组件: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>




Logo

前往低代码交流专区

更多推荐