vue中父组件改变子组件中的data

父组件:father.vue

<template>
    ...
    <button @click="changeChild">Change</button>
    <children ref="child"></children>
    ...
</template>

<script>
import children from ".../children"

export default {
    methods: {
        changeChild() {
            this.$refs.child.childData = true;    // 这句很重要
        }
    }
}
</script>

子组件:children.vue

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

效果:

在父组件中有一个按钮,点击这个按钮可以改变子组件 children 中的 childData 的值变为 true。

全部评论

相关推荐

05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务