我想获取中国地图,结果报错
const ret = await axios.get('http://127.0.0.1:8999/static/map/china.json')
问题在于:不能使用绝对地址,用相对地址,改成
const ret = await axios.get('http://localhost:8999/static/map/china.json')
console.log(ret)
想要显示中国地图,对其进行注册
const ret = await axios.get('http://localhost:8999/static/map/china.json')
console.log(ret)
this.$echarts.registerMap('china', ret.data)
const initOption = {
geo: {
type: 'map',
map: 'china'
}
}
this.chartInstance.setOption(initOption)
显示图片如下:
想显示全球的地图
const ret = await axios.get('http://localhost:8999/static/map/world.json')
console.log(ret)
this.$echarts.registerMap('world', ret.data)
const initOption = {
geo: {
type: 'map',
map: 'world'
}
}
this.chartInstance.setOption(initOption)
如果报错
Uncaught (in promise) AxiosError {message: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
检查是不是axios.get名字写错了