vue组件引用传参-子组件接受父组件传递过来的值

在父组件里面引入子组件

<template>
	<view class="content">
		<!-- 在页面进行引入(注意:这里是中文,所以是“‘’”引号) -->
		<mo-ban :han="'我是小涵涵'"></mo-ban>
	</view>
</template>

import moBan from '@/pages/moBan/moBan';
export default {
    
    
	components: {
    
    
		moBan
	}
}

子组件moBan.vue

<template>
	<view>
		<!-- 把传递过来的参数进行页面渲染 -->
		<text>我是引用模板中的文字的小憨憨{
    
    {
    
     han }}</text>
	</view>
</template>

<script>
export default {
    
    
	props: {
    
    
		//接受父元素传过来的参数
		han: {
    
    
			type: String,
			required: true
		}
	}
};
</script>

猜你喜欢

转载自blog.csdn.net/qq_42899245/article/details/107352881