您的位置:首页 > Web前端 > Vue.js

vue.js处理跨域问题

2019-02-18 11:47 197 查看
[code]第一步: 修改 config--->index.js
proxyTable: {
"/api":{
target:"http://localhost:3000",
changeOrigin:true,
pathRewrite:{
'^/api':''
}

第二步:min.js添加HOST:

[code]Vue.prototype.HOST='/api'

第三步:组件内的请求写法:

created(){
    var url = this.HOST+"/movie/top250";
    this.$axios.get(url,{
        params:{
        count:10,
        start:0
        }    
    })
    .then(res => {
        this.filterData(res.data);
    })
    .catch(error =>{
        console.log(error)
    })
}

第四步:配置文件修改后要重启vue.js

  //此种方式只适用于测试阶段,打包的时候不具备服务器,不能跨域了,后端解决

//注:要把main.js 中的全局请求地址注释掉。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: