uniapp + vue3重构项目第二弹

文章讲述了在使用uni框架进行Vue3页面跳转时,如何避免非props属性(id)传递导致的问题。通过将参数定义在组件上,正确使用defineProps接收props,解决了自动继承属性的问题,推荐给开发者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

警告

Extraneous non-props attributes (id) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.

在这里插入图片描述

原因

使用uni.navigateTo()跳转页面的同时进行传参

uni.navigateTo({
			url: `/pages/dev-info/dev-info?title=${dev.Name }&id=${dev.ID}`
		})

/pages/dev-info/dev-info 页面接收参数时,直接定义一个变量进行接收

<script setup>
const curDev = ref({
	title: '',
	id: ''
})

onLoad((option) => {
	console.log('option', option)
	curDev.value = option
})

</script>

解决

直接使用defineProps接收参数就可以了

<script setup>
	const props = defineProps({
		title: {
			type: String,
			
		},
		id: {
			type: String,
		}
	})
</script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值