当前位置: 首页 > news >正文

大新网站制作网站地图生成器哪个好

大新网站制作,网站地图生成器哪个好,网店运营流程步骤,如何用nat123做网站另一篇请求接口简单封装在api下的index.js 本片资源下载地址 本片封装了post get put请求#xff0c;重点在request.js文件 1.新增四个文件 2.根目录下的utils下的request.js封装uni.request()请求 注意 #xff1a;需要根据自己接口的 statusCode 状态码 、数据状态码…另一篇请求接口简单封装在api下的index.js 本片资源下载地址 本片封装了post get put请求重点在request.js文件 1.新增四个文件 2.根目录下的utils下的request.js封装uni.request()请求 注意 需要根据自己接口的 statusCode 状态码 、数据状态码 return_code 和提示信息 return_message 做对应替换 需要更改公共地址 需要注意store的token获取 需要注意 封装了get post put请求 需要其他的请求自行继续封装 import store from ../storelet baseUrl let isExisited falseconst $https {}switch (process.env.NODE_ENV) {case development:// 公共的地址开发baseUrl http://172.17.2.112:8080/breakcase test:baseUrl https://test.epen.ltd/breakcase production:baseUrl https://production.epen.ltd/breakdefault:baseUrl https://default.epen.ltd/ } console.log(baseUrl, baseUrl)function httpRequest(settings, opts) {const { loading, hasToken, toast, checkToken } optsconst token uni.getStorageSync(token_key)const hasUserInfo store.getters.hasUserInfoif (hasToken ! false) {settings.header[Token] token// if (!token) {// uni.showModal({// title: 提示,// content: 身份失效请重新登录,// complete: () {// uni.reLaunch({ url: /pages/index/index })// },// })// return// }}let showLoading loading ! falseif (showLoading) uni.showLoading({ title: 加载中..., mask: true })return new Promise(function (resolve, reject) {uni.request({...settings,success: (res) {const { statusCode, data } resconsole.log(接口返回的res, statusCode, res)if (showLoading) uni.hideLoading()// 判断 statusCode 是否是200 查看接口调用是否成功switch (statusCode) {case 200:breakcase 500:// reject({ statusCode: 500, return_message: 服务器重启中... })uni.showToast({title: data.return_message || 服务器重启中...,duration: 2000,icon: none,})returndefault:// reject({ statusCode: statusCode, return_message: 请求失败 })uni.showToast({title: data.return_message || 请求失败,请重试,duration: 2000,icon: none,})return}//在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示const result res.dataswitch (result.return_code) {case 0:// 成功的数据data状态码 则直接返回数据resolve(result)breakcase 4011:uni.clearStorage()if (hasUserInfo !isExisited !checkToken) {isExisited trueuni.showModal({title: 提示,content: 身份失效请重新登录,complete: () {uni.reLaunch({ url: /pages/index/index })},})} else {reject(result)}breakdefault:reject(result)if (toast ! false) showErrors(result)}},fail: (res) {console.log(请求fail, res)if (showLoading) uni.hideLoading()uni.showToast({title: res.return_message || 请求失败,请重试,duration: 2000,icon: none,})},})}) }function showErrors(res) {const { return_code, return_message } resswitch (return_code) {case 4004:uni.showToast({title: return_message,duration: 2000,icon: none,})breakdefault:uni.showToast({title: return_message || 请求失败,duration: 2000,icon: none,})} }function setParams(params) {let result []for (let p in params) {result.push(${p}${params[p]})}return ? result.join() }$https.get function (opts) {const { params, data, toast, hasToken, loading, checkToken } optsif (params) opts.url opts.url setParams(params)let defaultOpts {url: baseUrl opts.url,data: data,method: GET,header: {X-Requested-With: XMLHttpRequest,Accept: application/json,Content-Type: application/json; charsetUTF-8,},dataType: json,}return httpRequest(defaultOpts, { loading, toast, hasToken, checkToken }) }$https.put function (opts) {const { params, data, toast, hasToken, loading } optsif (opts.params) opts.url opts.url setParams(opts.params)let defaultOpts {url: baseUrl opts.url,data: data,method: PUT,header: {X-Requested-With: XMLHttpRequest,Accept: application/json,Content-Type: application/json; charsetUTF-8,},dataType: json,}return httpRequest(defaultOpts, { loading, toast, hasToken }) }$https.post function (opts) {const { params, data, toast, hasToken, loading } optsif (params) opts.url opts.url setParams(params)let defaultOpts {url: baseUrl opts.url,data: data,method: POST,header: {X-Requested-With: XMLHttpRequest,Content-Type: application/json; charsetUTF-8,},dataType: json,}return httpRequest(defaultOpts, { loading, toast, hasToken }) }export { $https, baseUrl } 3.pages/api/modules.js 注意api下 一个模块js文件 存放一个模块的接口方法 /*data为 {}请求参数params为 {}, 最后更改为url传参opts为 {loading: false,hasToken: false}其中loading为false不显示loading框hasToken为false, 请求不需要tokenreturn $https.get({url,data,params,...opts})return $https.post({url,data,params,...opts})*/ import { $https } from ../../utils/request // 获取学生列表 export function getStudentList(params) {return $https.get({url: main/stuWork/answersBySerial,params,loading: false,}) } // 获取练习下题目信息 export function getQuestionByWorkId(params) {return $https.get({url: main/work/queStatus/${params.workId},}) } // 获取练习下所有题目批改信息 暂不使用 export function getQuestionCorrectByWorkId(params) {return $https.get({url: main/resource/getQuestion,params,}) }// 提交单道题目批改结果 export function submitCorrectAnswer(data) {return $https.post({url: main/correction/subCorrResult,data,loading: false,}) }// 动态id获取练习信息 export function getExerciseInfo(id) {return $https.get(main/interaction/start/${id}) } // 直接get获取 export function getProductcategory() {return $https.get({url: api/v1/accident/productcategory/list,}) } // get参数获取 export function getInsurancecompany(params) {return $https.get({url: api/v1/accident/insurancecompany/list,params,}) } // post参数请求 export function postInsurance(data) {return $https.post({url: api/v1/accident/insurance/list,data,}) } 4.请求vue页面 templateviewviewobjData: {{objData}}/viewview stylemargin-top:50px;arrData:view v-foritem in arrData :keyitem{{item}}/view/view!-- button typeprimary clickget原生请求/buttonbutton typeprimary clickgetType封装后 async await获取/buttonbutton typeprimary clickpostType封装后 .then()获取/button --..button typeprimary clickget1utils完全封装--直接get/buttonbutton typeprimary clickget2utils完全封装--参数get/buttonbutton typeprimary clickpost1utils完全封装--post参数/button/view /templatescript import { getProductcategory, getInsurancecompany, postInsurance } from ../api/modules; export default {data() {return {value: 0,objData: {},arrData: []}},methods: {get() {uni.showLoading({title: 加载中...,mask: true,})uni.request({url: http://localhost:2222/yiiapp/order/list-all-web,data: {refund_status: 0,action: multiple_orders,order_type: 0,index: 0,limit: 10,status: 3,key: ,},header: {// 使用公众号的CookieCookie: _uab_collina162036568869229763220898; Hm_lvt_79ee0e9f63d4bd87c861f98a6d4979931621240284,1621300029,1621410251,1621411597; PHPSESSIDmpmdmr4d7vneg6tpmmgm130gu1; user_id3963; ZHBSESSIDe3aab6cf717a4d549c87735d0c39110e; Hm_lpvt_79ee0e9f63d4bd87c861f98a6d4979931621504639},method: POST,success: (res) {uni.hideLoading()if (res.statusCode ! 200) {return uni.showToast({title: 获取数据失败,icon: none,mask: true,})}console.log(原生获取res, res);this.objData res.data.data},fail: (error) {uni.hideLoading()uni.showToast({title: 请求接口失败,icon: none,})console.log(error);}})},async getType() {const res await this.$myRequest({url: yiiapp/order/list-all-web,})console.log(使用async await获取返回的参数, res);this.objData res.data},postType() {this.$myRequest({url: yiiapp/car-ins-stat/get-car-ins-stat,method: POST,data: {agency_id: 125,stat_date_type: 3,dim: self-team-insurancecompany}}).then(res {console.log(使用.then()获取返回的参数, res);this.arrData res.data})},changeType(e) {// console.log(e);this.value e.target.value},get1() {getProductcategory().then(res {console.log(res, res);this.arrData res.data})},get2() {getInsurancecompany({ productCategory: 7 }).then(res {console.log(res, res);this.arrData res.data})},post1() {let obj {insuranceCompany: ,insuranceName: ,pageIndex: 15,pageSize: 1,productCategory: }postInsurance(obj).then(res {console.log(res, res);this.arrData res.data})}} } /scriptstyle langscss button {width: 260px;margin-top: 2px; } /style5.成功接口请求 6.失败接口 404提示 接口调用成功200 但是data的状态码返回异常 做提示:
http://www.zqtcl.cn/news/862760/

相关文章:

  • 昆明网站建设价格自力教育
  • 黄冈网站推广软件视频下载孝感做网站xgsh
  • 用jsp做一网站的流程图互联网博客网站
  • 南宁一站网 给网站做营销微网站和网站同步像素
  • 如何建设一个视频小网站软件做网站
  • 小企业网站建设公司哪家好网站怎样设计网页
  • 那个网站做搬家推广比较好wordpress twenty eleven
  • 微站图片临淄信息网招聘最新信息
  • 投诉举报网站建设方案宠物网站 模板
  • 生小孩去什么网站做登记有特点的个人网站
  • 汉中市住房和城乡建设局网站学网站建设需要什么
  • 深圳网站建设外包公司排名网络引流怎么做啊?
  • 关于做暧暧的网站php 网站授权
  • 网站上添加子栏目wordpress群组
  • 一站式手机网站制作有没有代做ppt的网站
  • 西安火车站网站建设网站的设计需要什么
  • 弹幕网站开发代码欧洲人喜欢什么样的服务器
  • 有哪些做壁纸的网站好ftp如何备份网站
  • 网站如何推广出去wordpress foopen
  • 网站空格键代码台州椒江网站建设公司
  • node 网站开发 视频教程汉阳网站推广
  • 广西新农村建设工作专题网站怎样创建公司网站
  • 中国十大招商平台谷歌优化软件
  • 做任务领黄钻的网站中国采购网招标公告
  • 网站建设三层架构实训报告德阳市网站建设
  • 有免费建网站opencms wordpress
  • 行业网站做的好的wordpress要有数据库
  • 重庆智能网站建设哪里好怎么在微信做企业网站
  • 甘肃建设局网站丰都网站建设公司
  • 四川建设设计公司网站网站建设好的图片