1.index.html 引用
<script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak=你的key"></script>
2.页面使用
const state = reactive({
city:''
});
const getCurrentCity = () => {
// const map = new BMap.Map();
// 获取当前城市
const geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition((position) => {
const point = position.point;
// 根据坐标获取城市名
const geoc = new BMap.Geocoder();
geoc.getLocation(point, (result) => {
if (result) {
state.city = result.addressComponents.city || '长春';
weather(state.city)
}
});
});
};