鍍金池/ 問答/HTML/ vue-cli腳手架搭頁面,axios請求帶參數(shù)的api,怎么請求。

vue-cli腳手架搭頁面,axios請求帶參數(shù)的api,怎么請求。

用vue-cli搭的腳手架,

現(xiàn)在有api,但是他有個參數(shù)
{"CatId":238,"Similar":false,"Trend":false,"IsNew":false,"Sales":true,"SuppNo":"LKN","SuppCatId":0}
http://116.62.33.192:66/product/getproductdetaillist

照網(wǎng)上axion那么寫不知道參數(shù)要寫在哪里,

'/api': {
                target:'http://116.62.33.192:66/product/getproductdetaillist',
                changeOrigin:true, 
                pathRewrite:{
                    '^/api': '/api'
                }
            }
            
            
let postData = {'CatId': 238, 'Similar': false, 'Trend': false, 'IsNew': false, 'Sales': true, 'SuppNo': 'LKN', 'SuppCatId': 0}
export default {
  methods: {
    jsonpData: function () {
      this.$axios.post('/api', postData)
        .then(res => {
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}

這么寫他報404,不這么寫,他報405.

回答
編輯回答
遲月

如果是get請求,axios.get('接口地址',{params:{傳遞的參數(shù)}})

如果是post請求.axios.post('接口地址',傳遞的參數(shù)對象表示形式)

2017年5月16日 18:11
編輯回答
懷中人

請求方式試一試 Post和 Get,或者其他方法

2017年6月8日 05:52