在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue跨域訪問

vue跨域訪問

index.js配置

dev: {

env: require('./dev.env'),
port: 3000,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
      '/api': {
                ??target: 'http://192.168.3.200:8888/',
                ??changeOrigin: true,
                    autoOpenBrowser: true,
                    cssSourceMap: false,
                ??pathRewrite: {
                    ???'^/api': '/'
                    ??}
                ?}
},

下面是 頁面請求
created: function () {

this.$http.get('kbar_channel/page')
.then((res) => {
    debugger;
  this.newsList = res.data
}, (err) => {
  console.log(err)
})

},

我本地起的服務(wù)器 端口3000
想過要訪問 http://192.168.3.200:8888/kbar_channel/page這個(gè)接口
配置如上 但是請求的還是localhost
clipboard.png
這是為什么呢 求大神指點(diǎn)

回答
編輯回答
忠妾

地址應(yīng)該是http://192.168.3.200:8888/api/kbar_channel/page

2018年8月14日 14:21
編輯回答
傻丟丟

怎么好多提問都是這樣
完全沒按照配置寫

'/api': {   //匹配到/api才進(jìn)行代理
      target: 'http://192.168.3.200:8888/',  //目標(biāo)地址這里不應(yīng)該加/除非下面重寫'^/api/': ''
      changeOrigin: true,  //代理發(fā)送
      pathRewrite: {
           '^/api': '/'  //重寫地址 /api/user -> //user 所有你要把'/'改成''
          }
     }

你的配置的意思是
/api/kbar_channel/page -> http://192.168.3.200:8888///kbar_channel/page

'/api': {
      target: 'http://192.168.3.200:8888',
      changeOrigin: true, 
      pathRewrite: {
           '^/api': '' 
          }
     }

/api/kbar_channel/page -> http://192.168.3.200:8888/kbar_channel/page

2018年7月5日 07:56
編輯回答
浪婳
// 配置
proxyTable: {
            '/kbar_channel':{
                target:'http://192.168.3.200:8888',
                changeOrigin:true,
            }
},
//請求 
this.$http.get('/kbar_channel/page')
.then((res) => {
    debugger;
  this.newsList = res.data
}, (err) => {
  console.log(err)
})

按我這樣配置一下

2017年4月20日 23:04