我是靠谱客的博主 洁净口红,这篇文章主要介绍axios 实现跨域,现在分享给大家,希望可以做个参考。

1. mian.js 引用axios

import axios from 'axios'

Vue.prototype.$axios = axios

2.config/index.js 的dev中添加如下代码

proxyTable: {

    '/api': {

         target: 'http://127.0.0.1/hyhy/',//设置你调用的接口域名和端口号 别忘了加http

         changeOrigin: true,

         pathRewrite: {

              '^/api': '/'//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调             用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可

        }

    }

},

3.在页面中引用

this.$axios.post('/api/userlogin/login', Qs.stringify({ username: this.username, password: this.password }))

.then((response) => {

    console.log(response)

})

.catch((response) => {

    console.log(response)

})

 

最后

以上就是洁净口红最近收集整理的关于axios 实现跨域的全部内容,更多相关axios内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部