【发布时间】:2021-09-06 16:30:44
【问题描述】:
我有这个模板
我的问题是模板中的location.drawnfeatures 由于某种原因没有更新
我可以看到我从 console.log 获得了正确的数据,并且我在没有 'v-for' 的情况下进行了测试,并且代码有效
如果我输入v-if="location.drawnFeatures.length",我会收到错误消息说长度未定义..
我尝试在任何地方添加.value
为什么 vue3 不访问数据?
<ol-feature v-for="(feature, index) in location.drawnfeatures" :key="'feature'+uid+index">
<ol-geom-point :coordinates="feature.coordinates"></ol-geom-point>
位置定义如下:
props:{
locationData:Object,
},
setup(props){
const location = ref({
center:[0, 0],
zoom:5,
coordinates:null,
rotation: 0,
name:null,
title:null,
})
onMounted(() => {
location.value = props.locationData && props.locationData.location ? props.locationData.location : location.value
console.log(location.value)
});
}
我也尝试在setup() 中声明 prop
const locationData = toRef(props)
如果我这样做 console.log(locationData.value) 我得到未定义
但这也不起作用
【问题讨论】:
-
这可能是因为它没有在您的参考文献中初始定义。我猜
drawnfeatures来自您传递并重新分配给裁判的道具?尝试在您的参考文献中声明为空数组。 -
我不确定你的意思,我在我的问题中添加了道具部分。
-
我也只看到了访问
location.drawnfeatures的代码,但我没有看到定义location.drawnfeatures属性的代码。 -
locationDataprop 的值从何而来?异步 Ajax 调用可能吗?顺便说一句,将对象记录到浏览器控制台不起作用as you might expect -
location.drawnfeatures不是道具,locationData是