Axiso解决跨域访问 !!!!
生活随笔
收集整理的這篇文章主要介紹了
Axiso解决跨域访问 !!!!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先請檢查下你的 Vue 版本,
Vue2 和 Vue3 跨域方式不同:
首先在配置 config里面的index.js
proxyTable: {'/api': {// target: 'http://www. wuyushuo.com:8080',// target: 'http://47.100.210.195',target: 'http://127.0.0.1:8000/',changeOrigin: true,pathRewrite: {'^/api': '',//重寫,}}},然后在 axios中
let reqParams = {url: '/api/recruit/select/list',method: 'get',params: {size: this.size,page: 1,...queryObj,cityId: this.$route.query.cityId}};let res = await axios(reqParams);最后一定不要忘了在 min.js配置BaseUrl(看了很多文章 都沒有提到 解決了一天啊!!!!)
import Axios from 'axios'Vue.prototype.$axios = Axios Axios.defaults.baseURL = '/api' Axios.defaults.headers.post['Content-Type'] = 'application/json';Vue.config.productionTip = false關鍵代碼是:Axios.defaults.baseURL = ‘/api’,這樣每次發送請求都會帶一個/api的前綴
總結
以上是生活随笔為你收集整理的Axiso解决跨域访问 !!!!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot开发接口
- 下一篇: axios的get与post