How to implement cross-domain request data by webpack+vuex

after the scaffolding installed by vue+webpack, you want to request data for an address, but it is not successful. The operation is as follows:
modify the config/index.js file:

 proxyTable: {
        "v1":{
            target:" https://www.easy-mock.com/mock/5b61584fd0774b3c9ec5034c/example1",
            changeOrigin:true,
            pathRewrite:{
                "^/aa":"/aa"
            }
        }
    },

and then quote it in action.js,

export default{
      GET_IN_THEATERS:({dispatch,state,commit}) => {
      axios({url: "/aa"}).then(res => {
            console.log(res);
        })
    }
}

but the requested address is still http://localhost:8080/aa
. How can I set up the correct address to be requested?

Aug.05,2021

proxyTable: {

    '/mock':{
        target:' https://www.easy-mock.com',
        changeOrigin:true,
        pathRewrite:{
            '^/mock':'/mock'
        }
    }
},
:
axios({url: '/mock/5b61584fd0774b3c9ec5034c/example1'}).then(res => {
  console.log(res)
})

Brother, where did you paste it, don't change it


//
proxyTable: {
    '/mock':{
        target:' https://www.easy-mock.com',
        changeOrigin:true,
    }
},
//
export default{
      GET_IN_THEATERS:({dispatch,state,commit}) => {
      axios({url: 'http://localhost:8080/mock/5b61584fd0774b3c9ec5034c/example1'}).then(res => {
            console.log(res);
        })
    }
}

data has been obtained successfully. The main mistakes I made are as follows:
1, v1 should be changed to / aa, first of all, write the right path name, then add /
2, target path with multiple spaces
3, restart the service


clipboard.png


use nginx proxy after changing config/index.js. 5-minute tutorial: https://codeshelper.com/a/11.

Menu