myfirstboke

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

2019-06-27 09:26  WEB前端小菜鸟  阅读(4025)  评论(0编辑  收藏  举报

本地调试

 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是放静态文件的地方,这个文件夹会放在更目录下  所以放入这里面 直接相对路径就可以访问

 

 
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2021-10-24
  • 2021-05-26
  • 2021-11-19
  • 2021-12-03
  • 2021-12-04
猜你喜欢
  • 2022-02-07
  • 2021-08-10
  • 2022-12-23
  • 2021-04-02
  • 2021-08-14
  • 2021-09-27
相关资源
相似解决方案