请求数据:
// get请求
const get = (url) => {
return new Promise((resolve, rejecy) => {
if (!XMLHttpRequest) {
resolve(null)
}
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
try {
const data = JSON.parse(xhr.responseText)
resolve(data)
} catch (e) {
resolve(null)
}
}
}
})
}
export default {
// 获取地图资源json
getMapjson(adcodes = "100000") {
return get(`https://geo.datav.aliyun.com/areas_v3/bound/${adcodes}_full.json`)
},
getMapjsons(adcodes = "100000") {
return get(`https://geo.datav.aliyun.com/areas_v3/bound/${adcodes}.json`)
}
}
跨域问题:
在html页面中的head里面添加meta
<meta name="referrer" content="no-referrer">
请求结果: