vue 请求本地json文件出现的问题

本地调试

 this.$axios.get("http://localhost:8080/static/sichuan.json").then(geoJson => {})
这是请求四川的json地图文件,这个使用echarts中取 的四川数据,本地直接 就是8080直接调试就行
 
 
上线怎么搞
 
 
this.$axios.get(this.jsonUrl+'/static/sichuan.json').then(geoJson => {})
vue打包之后是index.html和static文件夹   所以我们直接放入static里面就行
 
 
这里需要注意一下 不能直接写成
this.$axios.get('https://bigdata.xxxxx.cn /static/sichuan.json').then(geoJson => {})
我试过不行,
 
main.js里面的
 
Vue.prototype.jsonUrl = 'https://bigdata.xxxxx.cn';
 
搞定
 
 为啥本地建立的json文件需要放置  /static 目录下??
我的理解是因为你打包之后只有index,html  和static文件夹  static是放静态文件的地方,这个文件夹会放在更目录下  所以放入这里面 直接相对路径就可以访问
 
 

猜你喜欢

转载自www.cnblogs.com/myfirstboke/p/11095135.html