uniapp调用组件方法和传参

文章描述:

uniapp如何调用组建方法和传递参数

页面

template

<template>
    <view class="content">
        <mian-index ref="demo"></mian-index>
        <view @tap="dataAction">button</view>
    </view>
</template>

script

import demo from '../../common/mask/demo.vue'
export default {
    data() {
        return {

        };
    },
    components:{
        'mian-index':demo
    },
    onLoad(e) {

    },
    methods:{
        dataAction:function(){
			var val = '123';
            this.$refs.demo.childMethod(val);
        }
    }
}

组件

script

export default {
    data(){
        return {
            
        }
    },
	onLoad(){
            
    },
    methods:{
        childMethod(val) {
            console.log('childMethod do...');
			console.log(val);
        }
    }
}

Console

childMethod do…
123

发布时间:2021/10/24

发表评论