Vue solves cross-domain invalidation by modifying index.js under config

modify the index.js configuration request address under config or fail according to the method on the Internet

The index.js code under

config is as follows:

proxyTable: {
      "/api/**":{
        target: "http://api.jisuapi.com",
        changeOrigin: true,
        pathRewrite:{
          "^/api": ""
        }
      }
    },

axois request code is as follows:

const actions = {
  getList ({commit}, msg){
    const start = Math.floor(Math.random() * 100)
    if (msg.channel && msg.type && msg.flag) {
      axios.get("/api/news/get?channel=" + msg.channel + "&start="+ start +"&num=10&appkey=272f8fcb40a13a6e")
      .then(res =>{
        commit("GET_NEWSLIT",{
          data: res.data.result.list,
          kind: msg.type
        })
        console.log(res.data)
      })
    }
  },

the page reported an error as follows

Thank you for your answers first!

Apr.29,2022

the direct access to the server path is 404.
it's not a problem with your configuration, it's that the interface doesn't exist, or there's a problem with passing parameters.
https://api.jisuapi.com/news/get path is 404

'/api': {
        target: 'http://api.jisuapi.com',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },

clipboard.png

clipboard.png


proxyTable: {
      '/api':{
        target: 'http://api.jisuapi.com',
        changeOrigin: true,
        pathRewrite:{
          '^/api': ''
        }
      }
    },
Menu