// 父组件
<div class="data">
<show-data :geoData="geoData" />
</div>
const getData = async (time, type) => {
const res = await getList(handleDate(time));
// console.log(res);
geoData.value = res.data.mapVal;
}
// 子组件
const props = defineProps({
geoData: {
type: Object as PropType<any>,
},
});
const geoData = ref(props.geoData);
console.log(geoData.value);
watch(props, (news, olds) => {
console.log(news.geoData);
console.log(olds.geoData);
geoData.value = news.geoData;
});
console.log(geoData.value);
最终watch里面的打印是有数据的,watch外面的打印为空
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧