鍍金池/ 問答/HTML/ vue proxyTable配置,瀏覽器為什么報(bào)錯(cuò)404?

vue proxyTable配置,瀏覽器為什么報(bào)錯(cuò)404?

通過配置peoxyTable實(shí)現(xiàn)跨域,但是瀏覽器報(bào)了404的錯(cuò)誤

proxyTable的配置

dev: {
            env: require('./dev.env'),
            autoOpenBrowser: true,
            assetsSubDirectory: 'static',
            assetsPublicPath: '/',
            proxyTable: {
            '/api': {
                target: 'http://172.16.2.207:8765', 
                changeOrigin: true,
                pathRewrite: {
                    '^/api': '/' 
                       
                }
            }
      },

請(qǐng)求

        this.$axios({
            method: "post",
            baseURL: "/api",
            url: "/uaa/oauth/token",
            data: {
                "scope": 'openid',
                "grant_type": 'password',
                "username": this.loginForm.user_name,
                "password": this.loginForm.pass
            },
            params: param,
            headers: {
                'Authorization': 'Basic ' + btoa(username+':'+password),
                'Content-Type':'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            },
            withCredentials:true,
            transformRequest: [data => {
                return qs.stringify(data);
            }],
            paramsSerializer: function(params) {
                return qs.stringify(params, {arrayFormat: 'brackets'})
            },
            auth: {
                username: username,
                password: password
            },

        })
        .then(request => {
            console.log(1);
        })
        .then(response => {
            console.log(2)
        })

瀏覽器報(bào)錯(cuò)
圖片描述

圖片描述

請(qǐng)問這是什么原因?

回答
編輯回答
柒槿年

把 pathRewrite 刪了重新 run 一下試試

2017年11月10日 19:13