Vue cross-domain request proxyTable problem

this is the addition of index.js to proxyTable in config

 proxyTable: {
       "/research": {
         target: "https://api.shenjian.io/?appid=c36a22e564a2954e&keyword=a&pageNo=1&pageSize=20",
 //
        changeOrigin: true,  //
         pathRewrite: {
           "^/research": "/c"   //
         }
       }
     }
           

add index.js interface in api

export default {
    songsearch: "/research"
  }

call the ajax function in

store

  mutations: {
    changeKeyword(state, x) {
      ajax(require.songsearch)
    }
   }

ajax

const ajax = function (url) {
  return new Promise(function (resolve, reject) {
    axios.get(url).then(res => {
      resolve(res);
    }).catch(reject);
  });
}

this is the result

I just started to learn that vue, wants to be a web player and has already got the api, but the axios request needs to be cross-domain, so it uses the proxyTable method to proxy, but the request address becomes the port number, why?

Apr.03,2021

after you configure it like this, the interface you access is https://api.shenjian.io/?appi..
and in the browser, although you see localhost:8080, it has actually been forwarded to the target you want to request through the agent

.
Menu