Fork me on GitHub

vue 2.x 之父组件修改子组件变量

有时候父组件触发的实际需要修改子组件内的data数据,这时候请给子组件绑定ref属性,在父组件触发时间内修改子组件的变量

<template>
  <div class="page">
    <Header 
      :page-type="getType(searchKey.tab)"
      ref="head"
      :fix-head="true"
      :need-add="true"/>

    <PostList
      :items="postList"
      ref="postlist"
      v-if="postList.length>0" />

    <GoToTop
      ref="gototop"
      :flag="flag"/>
  </div>
</template>

  <!-- 在方法中调用this.$refs即可获取到ref绑定的组件或者DOM -->
  // 收起菜单
  this.$refs.head.show = false;
posted @ 2019-09-21 17:40  较瘦  阅读(1188)  评论(0编辑  收藏  举报
知识点文章整理