vue在本地跑,run个dev啥的,会面临到跨域问题
解决:在config的index.js文件里,dev模块加上:
proxyTable: {
'/api': {
target:'http://api_zsc.idc.gcsci.net/vue',
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
}
}
像这样:
target里写后端给你的API接口路径
然后在项目里,正常写就可以了。
举个栗子:
如果接口是:http://api_zsc.idc.gcsci.net/mobile/getTrends
只需在axios的url里写 ‘/mobile/getTrends’
就可以了。
头发不易,且敲且珍惜