1、在vue项目中axios涉及跨域,一直报404错误,不知道是哪里问题。
2、请输入代码
index.js
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
配置项:
dev: {
env: require('./dev.env'),
port: 8081,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'https://api.douban.com/v2',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
调用:
this.axios.get('/book/1220562').then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
梦里花落0921
相关分类