Article From:https://segmentfault.com/q/1010000015622839
Question:

The project uses the vue-cli family barrel, the asynchronous request Axios, because the project has just upgraded from HTTP to HTTPS, so it tested the interface access problems, and found a problem:
The requested URL will bring a local domain name in front of it (this is local debugging, if it is online to debug the corresponding online domain name). Why is this?

I configured the following conversion in the config/index.js file.

dev: {
    env: require('./dev.env'),
    port: 8082,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
        '/apis':{
            target:'http//api.open.test.ai',
            changeOrigin:true,
            pathRewrite:{
                '^/apis':'/apis'
            }
        }
    }
}

And then the request is like this.

this.$axios.post('/apis/readingcutupload', {
    file: data
}).then(res => {
    if (res.data.result === 1) {
        t.success('Upload success! ");} else {T.Error (res.data.msg);}})

But why is the request on the console like this? “It seems that it has not been converted.

Answer 0:

The default is a relative path, such asaxios.get('/api/login')。Since you have used vue-cli, recommend the configurationproxyTable,Make an agent forwarding and set it in file config/index.js.

Leave a Reply

Your email address will not be published. Required fields are marked *