1.代码
created: function() {
this.axios
.get("/src/assets/Merch.json")
.then(response => {
let Merchs = response.data.Merch;
/* this.answers = response.topic_answer; */
console.log(this.answers);
console.log(Merchs);
})
.catch(error => {
console.log(error);
});
2.问题提示
xhr.js?ec6c:178 GET http://localhost:8080/src/assets/Merch.json 404 (Not Found)
Error: Request failed with status code 404
at createError (createError.js?16d0:16)
at settle (settle.js?db52:18)
at XMLHttpRequest.handleLoad (xhr.js?ec6c:77)
vue-cli 2.X版本可以,换到3.0就会遇到这个问题,求大神解释一下
vue/cli 3和之前的架构不一样了,有点类似于create-react-app脚手架的组织方式。
如果你是相对路径引入的话,webpack会帮你处理,官方也建议使用相对路径。
绝对路径的的话,相关文件需要放到public目录下。