uni-app $refs的基本用法

时间:2019-01-28 13:57:21   收藏:0   阅读:6972

$refs的基本用法

一个对象(Object),持有注册过 ref 特性 的所有 DOM 元素和组件实例。

 

 

技术分享图片
<template>
    <view class="container" style="background: #0FAEFF;">
        <view class="child"> hi {{showModal}}</view>
    </view>
</template>
<script>
    export default {
        props: {
            showModal: {
                type: String,
                default: ‘hello‘
            }
        },
        data() {
            return {
                childdata: ‘child value‘
            };
        },
        methods: {
            sayHello() {
                console.info("--child:--" + this.showModal);
            }
        }
    }
</script>
 
child
技术分享图片
<template>
    <view class="container">
        <child :showModal="showModal" ref="vref"></child>
        
           <button @tap="refMethods" type="primary" >点击</button>
    </view>
</template>

<script>
    import child from "../../components/child.vue"

    export default {
        components: {
            child
        },
        data() {
            return {
                showModal: " parent say",
                parentValue: ‘‘,
                syncDate: ‘ p syncDate‘
            };
        },
        methods: {
            refMethods() {
                var child = this.$refs.vref;
                child.sayHello();
            }

        }
    }
</script>

<style>

</style>
parent

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!