ITeye博客

axios 跨域问题解决

e_e · 2018-10-18 09:27 · vue · axios · Web前端 · Markdown

1.main.js 引入axios

import axios from 'axios';
Vue.prototype.$http = axios;

 

2. 发起post请求

methods: submitForm:function(){
        this.$http.get("/user/find?id=1").then(r=> console.log(r.data));
this.$http.defaults.headers.post['Content-Type']='application/json;charse=UTF-8';
this.$http.post(this.url, JSON.stringify(this.user)).then((response) => {
            console.log(response.status);
console.log(response.statusText);
}, (response) => {
        });
}
}

 

3. index.js 里配置代理

    请求的目标地址是http://localhost:80/user/add

proxyTable: {
    '/user': {
        target: 'http://localhost:80',
changeOrigin: true,
pathRewrite:{
            '^/user/':'/'
}
    }
},

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。