uni-ui icon indicating copy to clipboard operation
uni-ui copied to clipboard

VUE3中二次封装uni-data-picker组件,多层级联的值没有回填text

Open w840980261 opened this issue 3 years ago • 0 comments

背景:使用的vue3.2的script setup语法糖,变量由外部通过props传入,watch监听后赋值,该组件中使用了多个uni-data-picker组件,localdata只有一层的组件回填text值正常,多层的地区选择器回填text无效。 排查: 控制变量,将赋值变为定值后,组件传参改为指定变量,后有如下代码

const props = defineProps({
	value: Object
});
const areaId = ref();

console.log('1');
// areaId.value = 3501;

setTimeout(() => {
	console.log('3');
	// areaId.value = 3503;
}, 500);

watch(
	() => props.value.areaId,
	val => {

		console.log('2');
		areaId.value = 3502;

		setTimeout(() => {
			console.log('4');
			// areaId.value = 3504;
		}, 500);
	}
);

其中控制台正常按照1234顺序打印,log后的赋值代码分别释放注释,其中仅有log2后的代码无法回填,其他三处均可正常触发picker的回填text。 后又尝试了nextTick如下代码:还是无法回填

watch(
	() => props.value.areaId,
	async val => {
		console.log('2');
		await nextTick()
		areaId.value = 35;
	}
);

w840980261 avatar Apr 11 '22 07:04 w840980261