vue中父组件获取子组件的方法

关键词:ref

在子组件child.vue中,有两个数据:

data() {
    return {
        a:1,
        b:2,
    }
}

在父组件father.vue中,使用子组件:

<child ref="child" .../>

<script>
...
let child_a = this.$refs.child.a
let child_b = this.$refs.child.b

重点是父组件的两个地方,先用 ref 属性标识子组件,然后用 this.$refs 获取子组件

猜你喜欢

转载自blog.csdn.net/romeo12334/article/details/82849722