Gin-vue 跨域
vue
安装
npm install axios --save
在main.js中引入axios插件 ,并设置axios全局配置
import Axios from 'axios'
Vue.prototype.$axios = Axios
Axios.defaults.baseURL = 'http://localhost:9090'
Axios.defaults.headers.post['Content-Type'] = 'applicaation/json'
config文件夹中的index.js中添加代理配置
proxyTable: {
'/': {
target: 'http://localhost:9090', // gin访问地址
changeOrigin: true, //送请求头中host会设置成target
}
}
.vue文件使用axios
get请求:
this.$axios.get('/user/getAll')
.then(res => {
console.log(r