api.js
// 获取json文件
export const getJson = function (method) {
return new Promise((resolve, reject) => {
axios({
method: 'get',
url: method,
dataType: "json",
crossDomain: true,
cache: false
}).then(res => {
resolve(res)
}).catch(error => {
reject(error)
})
})
}
vue文件中获取json文件
import {getJson} from '@/api/api'
// 上面的图
getJson(`static/json/hebei/文件名`).then(res => {
echarts.registerMap('hebei', res.data);
});
本文介绍如何在Vue项目中使用axios库获取JSON文件,并通过Promise处理响应数据,最终应用到ECharts地图数据注册中。
5856

被折叠的 条评论
为什么被折叠?



