如果HTML报错如下: 就是存在了跨域问题
解决方法:
在项目的根目录下创建vue.config.js文件
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:7788',
ws: true,
changeOrigin: true,
pathRewirte:{ //路径重写
'^/api':''
}
},
// 除了可以写api还可以写其他接口 如foo
'/foo':{
target:'http://localhost:3001'
}
}
}
}
在.vue中发起请求数据时
methods: {
//2.请求首页数据
async getIndexData() {
let {data:res} = await http('/api/你的请求路径');
}
},