1.首先需要在父组件中调用子组件,并在子组件的属性中写上传值的数据
这是父组件的wxml界面,其中find_all_teachers为子组件,分别传值teacher_list
<find_all_teachers teacher_list="{
{teacher_list}}"></find_all_teachers>
2.在子组件的find_all_teachers.json中加入
{
"usingComponents": {
},
"component": true
}
父组件的json中加入
{
"usingComponents": {
"find_all_teachers": "/pages/student/find_all_teachers"
}
}
3.子组件find_all_teachers.js中加入properties,properties中的名字即为之前父组件传值写的名字teacher_list
const app = getApp()
Component({
data: {
},
options:{
addGlobalClass: true,
},
properties:{
teacher_list: {
type: Object,//格式有Object、Array、String等
value: ''
}
},
methods:{
}})
4.在子组件页面调用数据teacher_list
<view wx:for="{
{teacher_list}}" >
</view>