在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue proxyTable 配置問題

vue proxyTable 配置問題

以前解決跨域問題都是后臺設(shè)置好了 Access-Control-Allow-Origin 之后,我就可以在直接調(diào)用所有接口都不跨域了

現(xiàn)在用了vue-cli些vue項(xiàng)目,也知道是在config的index.js文件里面更改,
但是為什么我這樣寫的

    dev: {
        env: require('./dev.env'),
        port: 8080,
        autoOpenBrowser: true,
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {
            '/index':{
                target:'http://線上接口',
                changeOrigin:true,
                pathRewrite:{
                    '^/index':''
                }
            },
            '/ms':{
                target: 'https://www.easy-mock.com/mock/592501a391470c0ac1fab128',
                changeOrigin: true
            }
        },
        // CSS Sourcemaps off by default because relative paths are "buggy"
        // with this option, according to the CSS-Loader README
        // (https://github.com/webpack/css-loader#sourcemaps)
        // In our experience, they generally work as expected,
        // just be aware of this issue when enabling this option.
        cssSourceMap: false
    }
this.$axios({
    method: 'post',
    url:'/index.php?mod=investment&code=check_invest_user',
    data:params
}).then((res)=>{
    console.log(res.data);
    if(res.data.errCode==0){

    }else if(res.data.errCode==1){
        this.$alert(res.data.retData.msg);
    }else if(res.data.errCode==2){
        this.$router.push('/login');
    }
});

調(diào)用接口的時候?yàn)g覽器請求的就變成了本地的
http://localhost:8080/index.php?mod=investment&code=check_invest_user

圖片描述

補(bǔ)充說明:
我重啟下npm run dev 接口可以調(diào)成功了
但是返回的數(shù)據(jù)是空的
圖片描述

之前后臺有設(shè)置過Access-Control-Allow-Origin
如果我把線上接口直接寫在 axios 里面url里 就不會有問題。。。數(shù)據(jù)都能拿到
圖片描述

回答
編輯回答
葬憶

pathRewrite配置的問題。要么注釋掉,要么如下面這樣寫

   proxyTable: {
        '/index':{
            target:'http://192.168.6.88',
            changeOrigin:true,
            pathRewrite:{
                '^/index':'index'
            }
        }
    },

重新run項(xiàng)目就好了

2018年9月12日 08:23
編輯回答
青黛色

你的配置的意思,你都沒按配置寫

/index/getUser -> http://線上接口/getUser
2018年5月13日 04:00