VUE跨域问题
vue-cli項(xiàng)目中,解決跨域問題。
在config > index.js 文件中的proxyTable里邊添加'/api'配置
proxyTable: {'/api': {// 跨域域名target: 'http://www.xxxxx.cn',// 是否跨域changeOrigin: true,pathRewrite: {'^/api': ''}} },在vue組件中使用
methods: {// 加載數(shù)據(jù)getUserInfo () {this.$axios.get('api/mall/servlet/json?funcNo=3040')// this.$axios.get('http://www.xxxxx.cn/mall/servlet/json?funcNo=3040').then(this.handleGetUserInfoSucc).catch(error => console.log(error))} }需要重新運(yùn)行項(xiàng)目,不然會(huì)報(bào)錯(cuò)
重新運(yùn)行項(xiàng)目后本地開發(fā)就不會(huì)出現(xiàn)跨域問題了。
當(dāng)項(xiàng)目打包,放到服務(wù)器上,會(huì)報(bào)錯(cuò)
Failed to load resource: the server responded with a status of 404 (Not Found)開發(fā)的時(shí)候用的dev_server只針對(duì)開發(fā)用的,打包后dev_server這塊配置的請(qǐng)求代理已經(jīng)無效。
這時(shí)直接將域名放到get中,打包放到服務(wù)器
methods: {// 加載數(shù)據(jù)getUserInfo () {// this.$axios.get('api/mall/servlet/json?funcNo=3040')this.$axios.get('http://www.xxxxx.cn/mall/servlet/json?funcNo=3040').then(this.handleGetUserInfoSucc).catch(error => console.log(error))} }總結(jié)
- 上一篇: 学习Python语言 基础语法:变量的基
- 下一篇: Centos 7 下安装PHP7.2(与