get 路由带参数(无参数也参照此写法,替换接口地址就行)
this.axios({ method: 'get', headers: { 'Content-Type': 'application/json; charset=utf-8', token: this.answerData.token,//请求头需要携带的token,不需要则不写 }, url: `${process.env.VUE_APP_HOST}/h5/questionnaire/user/info/${this.answerListData.questionnaireId}`,//接口地址与参数 }).then( (res) => { let { code, data, msg } = res.data; if (code === 0) { //this.answerInformation与this.answerStatus为return声明的变量 this.answerInformation = data; this.answerStatus = 1; //已答题 } else { this.$notify({ type: 'warning', message: msg }); } }, (err) => { console.log(err); }, );
get 带参数
this.axios({ method: 'get', headers: { 'Content-Type': 'application/json; charset=utf-8', token: this.answerData.token,//请求头需要携带的token,不需要则不写 }, url: `${process.env.VUE_APP_HOST}/h5/questionnaire/user/list?page=1&pageSize=10000`,//${process.env.VUE_APP_HOST}/h5/questionnaire/user/list为路由地址,page与pageSize为需要传给后台的参数 }).then( (res) => { let { code, data, msg } = res.data; if (code === 0) { //this.questionnaireList为return中声明的变量 this.questionnaireList = data.list; } else { this.$notify({ type: 'warning', message: msg }); } }, (err) => { console.log(err); }, );
post带参数
this.axios({ method: 'post', headers: { 'Content-Type': 'application/json; charset=utf-8', token: this.answerData.token, }, url: `${process.env.VUE_APP_HOST}/h5/submit/questionnaire`, data: JSON.stringify({ questionnaireId: answerListData.questionnaireId, submitQuestionnaireDetailDTOS, totalScore: totalScoreNum, }),//data为需要传给后台的参数 }).then( (res) => { let { code, data, msg } = res.data; if (code === 0) { //this.showDialog为return中声明的变量 this.showDialog = false;//关闭弹框 } else { this.$notify({ type: 'warning', message: msg }); } }, (err) => { console.log(err); }, );
标签:vue,err,get,res,token,code,msg,post,data From: https://www.cnblogs.com/lengfang/p/16798715.html