需求:
在父组件的一个事件可以改变子组件中的 openData 的值变为 true。

废话不多说,直接上代码:

父级页面:


<template>
  <div>
    <div @click="changeChild">按钮改变子组件数据</div>
    <children ref="childrenDom"></children>
   </div>
</template>
 
<script>
import Childrens from ".../childrens"
export default {
components: {
    Childrens
  },
    methods: {
        changeChild() {
            this.$refs.childrenDom.openData = true
        }
    }
}
</script>

注: this.$refs.childrenDom就是指的childrenDom DOM元素
子组件页面:

<script>
export default {
    data() {
        openData: false
    }
}
</script>

  

相关文章:

  • 2022-12-23
  • 2022-02-04
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案