vue使用axios跨域提示404

请求的这个地址http://www.weather.com.cn/data/cityinfo/101010100.html
是我哪里写的不对吗? 提示GET http://localhost:8080/api/cityinfo/101010100.html 404 (Not Found)

assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
        '/api': {
           target: "http://www.weather.com.cn/data",
           changeOrigin:true,
           pathRewrite:{
             '^/api':''
           }
        }
    },
methods: {
    weather () {
      this.$http.get('/cityinfo/101010100.html').then(res => {
        console.log(res)
      })
    }
}
阅读 15.4k
4 个回答

代码有问题,按下面这样子修改就没有问题了。但生产环境下需要配其他方式代理
clipboard.png

    proxyTable: {
      '/api': {
        target: "http://www.weather.com.cn/",
        changeOrigin:true,
        pathRewrite:{
          '^/api':'/data'
        }
      }
    },
import axios from 'axios'
export default {
  name: 'App',
  mounted () {
    axios.get('/api/cityinfo/101010100.html').then(res => {
      console.log(res)
    })
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题