美文网首页
vue2.0引入本地json文件一直报404错误

vue2.0引入本地json文件一直报404错误

作者: 大胡子111 | 来源:发表于2018-09-26 10:37 被阅读20次
404错误.png 项目目录.png

似曾相识的错误,尝试过放到src目录下,尝试了放到根目录下(现在就是在根目录下)这个文件目录怎么调换都是报错。

解决:静态资源要放到static文件夹里!!!
项目目录1.png

js代码

 export default {
    name: 'home',
    data () {
      //存放数据
      return {

      }
    },
    //生命周期 - 挂载完成(可以访问DOM元素)
    mounted(){
      this.showData();
    },
    //存放方法
    methods:{
      showData:function () {
        this.$http.get("http://localhost:8080/static/data1.json").then(response => {
          console.log(response.body);
        }, response => {
        });
      }

    },
    ////import引入的组件需要注入到components对象中才能使用"
    components: {
      rrheader,
      rrbottom
    },
  }

相关文章

网友评论

      本文标题:vue2.0引入本地json文件一直报404错误

      本文链接:https://www.haomeiwen.com/subject/wtldoftx.html