1、vue3以下版本,将本地文件放到static文件夹下
this.$axios.get('static/XXX.json').then((res) =>{})
2、vue3及以上版本,取消了static文件夹,静态文件改存到public文件夹下了。
this.$axios.get('/data/XXX.json').then((res){})
注意路径不能写成'public/data/XXX.json',会报404错误
转发api路径代理设置:新版本需手动创建vue.config.js文件
//在根目录下创建vue.config.js,如下配置:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:8080', //路径指向本地主机地址及端口号
ws: true,
changeOrigin: true,
pathRewrite:{
'^/api': '/data' //路径转发代理
}
}
}
}
}
将请求路径进行修改
this.$axios.get('/api/XXX.json').then((res)=>{})