原因:该操作是异步,我以为下面的方式可以解决掉了,谁知道safair不支持:
navigator.permissions.query({ name: "geolocation" }).then((res) => {
// granted:成功 denied:失败
if (res.state === "granted") {
}
});
接着我又换了另一种方式,这种方式的兼容性更好一些:
// 成功的时候执行
successCallback () {
},
// 失败的时候执行
handleLocationError () {
},
// 判断浏览器是否允许获取地址
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.successCallback, this.handleLocationError, { maximumAge: 15000, timeout: 10000, enableHighAccuracy: true });
} else {
this.handleLocationError();
}