在store中存储了longitude和latitude后,在detail-map中一直取不到,导致百度地图总显示几内亚----- 问题原因: 误把经纬度数据定义为响应式数据,导致打印一直是undefined
const mapRef = ref();
const { longitude, latitude } = useDetailStore()
// const { longitude, latitude } = storeToRefs(detailStore)
console.log(longitude);
// console.log(longitude);
// const longitude = ref(position.longitude)
// const latitude = ref(position.latitude)
// console.log(longitude);
解决办法:
直接解构出来使用即可
const { longitude, latitude } = useDetailStore()
onMounted(() => {
const map = new BMapGL.Map(mapRef.value); // 创建地图实例
const point = new BMapGL.Point(longitude, latitude); // 创建点坐标
map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
var marker = new BMapGL.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
})