get請求數據
用params傳參數是一個對象
//請求數據 insuranceClassifyData () { this.$http.get(Apis.INSURANCE_CLASSIFY, { params: { pageNo: 1, sortBy: 'weight:desc' } }) .then(resp => { if (resp.data.statu === 200 && resp.data.message === 'SUCCESS') { console.log(resp.data.data.list) this.classifyData = resp.data.data.list } }) .catch(resp => { console.log(resp) }) },
post和put上傳數據
/* * 表單提交事件/新建/修改 * formName:要提交的那個表單的表單對象 */ submitClassifyForm (formName) { if (formName.cargoCategoryId) { this.$http.put(Apis.INSURANCE_CLASSIFY + `/${formName.cargoCategoryId}`, formName) .then(resp => { location.reload() //成功以后刷新頁面 }) .catch(resp => { console.log(resp) }) } else { this.$http.post(Apis.INSURANCE_CLASSIFY, formName) .then(resp => { location.reload() }) .catch(resp => { console.log(resp) }) } },
delete刪除數據
// 刪除事件 deleteClassify (data) { this.$http.delete(Apis.INSURANCE_CLASSIFY + `/${data.cargoCategoryId}`) .then(resp => { location.reload() }) .catch(resp => { console.log(resp) }) },
轉載:https://www.jianshu.com/p/445f0a712435