vue通过修改config下的index.js解决跨域无效

按照网上的方法,修改config下的index.js 配置请求地址,还是请求失败

config下的index.js代码如下:

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

axois请求代码如下:

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)
      })
    }
  },

页面报错如下
图片描述

先感谢各位的回答!!!

阅读 4.3k
2 个回答

服务器路径直接访问都是404
不是你配置有问题,是接口本来就不存在,或者你传参有问题。
https://api.jisuapi.com/news/get 路径是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': ''
        }
      }
    },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题