Uniapp中父子页面传值

效果

在这里插入图片描述
在这里插入图片描述

实现

A页面

点击图一按钮进入图二页面

<view class="cu-form-group margin-top">
			<button class="cu-btn sm bg-gradual-green" style="margin-left: 70%; " @click="selectMaterial">
				选择物料
			</button>
		</view>
selectMaterial() {
				let _this = this
				uni.navigateTo({
					url: '/pages/product/PartsMaterialSelect',
					events: {
						materialData: function(data) {
							console.log('返回值', data)
						}
					}
				})
			},

B页面

B页面绑定了C页面,主要用来传值
同时加载B页面时调用后端接口,返回查找值

view class="scrollbox">
			<scroll-view scroll-y="true">
				<MaterialCardParts :materials="materials"></MaterialCardParts>
			</scroll-view>
		</view>
		<view class="padding-xs">
			<uni-pagination :current="currentPage" :total="totals" :pageSize="total" @change="handlePage">
			</uni-pagination>
			<text style="margin-left: 28%;">总数:{{totals}}条,每页最多:{{total}}</text>
		</view>

//获取所有的MaterialCode
			getAllMaterialCode() {
				let _this = this;
				let params = {
					pageIndex: _this.currentPage,
					pageSize: _this.total
				};
				uni.request({

					url: apiUrl + '/GetAllMaterialCode',
					method: "POST",
					data: params,
					success: (res) => {
						console.log('返回值2', res.data.data)
						_this.materials = res.data.data.ret;
						_this.totals = res.data.data.pageTotal
					},
					fail: (res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					},
				})
			}

C页面(B的子页面)

<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
				@selection-change="selectionChange">
				<uni-tr>
					<uni-th width="80" align="center">物料编码</uni-th>
					<uni-th width="80" align="center">物料名称</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in materials" :key="index">
					<uni-td>{{ item.materialCode }}</uni-td>
					<uni-td>
						<view class="name">{{ item.materialName }}</view>
					</uni-td>
				</uni-tr>
			</uni-table>

props: {
			materials:{
				 type: Array,
				 default: () => []				
			},
			func: {
				type: Object,
				value: null
			}
		}

思路

父页面可以将获取到的数据作为props属性传递给子页面。在父页面中,将数据作为props属性的值传递给子页面组件。在子页面组件中通过props接收数据并在页面中使用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晚风偷吻云朵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值