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

鍍金池/ 問答/HTML/ vue在開發(fā)模式下,怎么改變向后臺發(fā)送請求的默認地址

vue在開發(fā)模式下,怎么改變向后臺發(fā)送請求的默認地址

向后臺發(fā)送請求現(xiàn)在的寫法

    this.$http.get('http://1.1.1.1:8080/product/getAllProducts?page=0')
      .then((response) => {
        me.tableData = response.body.data.content
      })
      .catch(function (response) {
        /**
         * todo:此處待補充錯誤處理 
         * */
      })

我希望改成下面寫法但是效果還是http://1.1.1.1:8080/product/getAllProducts?page=0

      this.$http.get('product/getAllProducts?page=0')
      .then((response) => {
        me.tableData = response.body.data.content
      })
      .catch(function (response) {
        /**
         * todo:此處待補充錯誤處理 
         * */
      })

為此,我改了config/index.js文件中的

dev: {
    proxyTable: {
      '/api': {
        target: 'http://1.1.1.1:8080',
        changeOrigin: true
      }
}
   

但是并不能實現(xiàn)我想要的效果,求助求助

注意:我用的是vue-resource,怎么寫呢?而且我就是開發(fā)模式下請求需要指定地址,在build模式下正常使用localhost

回答
編輯回答
伴謊

webpack-dev-server可以配置代理,

devServer: {
    proxy: {
        '/some/path*': {
            target: 'https://other-server.example.com',
            secure: false,
        },
    },
},
axios可以全局配置axios.defaults.baseURL = 'http://api.exmple.com';  

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['content-Type'] = 'appliction/x-www-form-urlencoded';

2018年7月5日 19:18
編輯回答
真難過
this.$http.get('product/getAllProducts?page=0') 

請求前面少了一個'/',改成

this.$http.get('/product/getAllProducts?page=0'),

其實可以控制臺調(diào)試一下,看看接口請求的詳細信息,一步一步找原因可以找到的。

2017年5月27日 17:04