即兴添加一下

Vue 子组件修改父组件传递过来的值

实现效果:通过点击选中的按钮控制左边的树是否进行展示

 

 

 

 

子组件篇:

        <el-button v-if="isShowTree&hasTree"  type="text" icon="btn-arrow iconfont icon-icon_arrow_left" style="margin-left:-30px;margin-top:-15px;position:absolute" @click="isShow()"></el-button> 
        <el-button   v-if="!isShowTree&hasTree" type="text" icon="btn-arrow iconfont icon-icon_arrow_right" style="margin-left:-25px;margin-top:-15px;position:absolute" @click="isShow()"></el-button> 

 属性接收传递过来的变量:

 

 

 定义触发改变父组件传递过来的值的事件:通过this.$emit()的方式调用父组件的方法达到改变子组件修改父组件传递过来值的效果

this.$emit()可以传递多个参数,第一个参数是调用的方法名,后面的则是你调用方法所需传递的参数

      isShow(){
        this.$emit("isShow");
      }

  

父组件篇:

<filter-Form :isShowTree="isShowTree" :hasTree="hasTree" @isShow="isShow" ></filter-Form>

data中定义数据类型:

 

 

 methods中定义点击事件的方法:

isShow(){ 
            this.isShowTree=!this.isShowTree;
        }

  

posted @ 2022-08-29 17:22  我本梁人  阅读(309)  评论(0编辑  收藏  举报