1、在vue项目中axios涉及跨域,一直报404错误,不知道是哪里问题。2、请输入代码index.jsimport 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) })
1 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
地址写错了, 正确是这个 /api/book/1220562
this.axios.get('/api/book/1220562').then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
添加回答
举报
0/150
提交
取消