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

用易语言做网站抢购软件做电商从哪里入手

用易语言做网站抢购软件,做电商从哪里入手,58网站怎么做才有客户问,凡科删除建设的网站文章目录 前言一、创建自定义配置的实例二、掌握返回的结果结构三、拦截器相关用法四、异常处理相关五、取消请求的方式总结 前言 书接上文#xff0c;目标对Axios的更多功能和特性熟练与提高。 一、创建自定义配置的实例 axios可以创建自定义配置的实例#xff0c;可以试试… 文章目录 前言一、创建自定义配置的实例二、掌握返回的结果结构三、拦截器相关用法四、异常处理相关五、取消请求的方式总结 前言 书接上文目标对Axios的更多功能和特性熟练与提高。 一、创建自定义配置的实例 axios可以创建自定义配置的实例可以试试这种方式为以后封装工具类做准备 axios.create([config]) const instance axios.create({baseURL: https://some-domain.com/api/,timeout: 1000,headers: {X-Custom-Header: foobar} });可用的实例方法 Instance methodsaxios#request(config) axios#get(url[, config]) axios#delete(url[, config]) axios#head(url[, config]) axios#options(url[, config]) axios#post(url[, data[, config]]) axios#put(url[, data[, config]]) axios#patch(url[, data[, config]]) axios#getUri([config])二、掌握返回的结果结构 只有详细的知道返回结果才能在实战中处理各种情况。 {// data is the response that was provided by the serverdata: {},// status is the HTTP status code from the server responsestatus: 200,// statusText is the HTTP status message from the server response// As of HTTP/2 status text is blank or unsupported.// (HTTP/2 RFC: https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.4)statusText: OK,// headers the HTTP headers that the server responded with// All header names are lower cased and can be accessed using the bracket notation.// Example: response.headers[content-type]headers: {},// config is the config that was provided to axios for the requestconfig: {},// request is the request that generated this response// It is the last ClientRequest instance in node.js (in redirects)// and an XMLHttpRequest instance in the browserrequest: {} }例 axios.get(/user/12345).then(function (response) {console.log(response.data);console.log(response.status);console.log(response.statusText);console.log(response.headers);console.log(response.config);});三、拦截器相关用法 // Add a request interceptor axios.interceptors.request.use(function (config) {// Do something before request is sentreturn config;}, function (error) {// Do something with request errorreturn Promise.reject(error);});// Add a response interceptor axios.interceptors.response.use(function (response) {// Any status code that lie within the range of 2xx cause this function to trigger// Do something with response datareturn response;}, function (error) {// Any status codes that falls outside the range of 2xx cause this function to trigger// Do something with response errorreturn Promise.reject(error);});//移除拦截器const myInterceptor axios.interceptors.request.use(function () {/*...*/});axios.interceptors.request.eject(myInterceptor);//自定义实例增加拦截器const instance axios.create();instance.interceptors.request.use(function () {/*...*/});四、异常处理相关 axios.get(/user/12345).catch(function (error) {if (error.response) {// The request was made and the server responded with a status code// that falls out of the range of 2xxconsole.log(error.response.data);console.log(error.response.status);console.log(error.response.headers);} else if (error.request) {// The request was made but no response was received// error.request is an instance of XMLHttpRequest in the browser and an instance of// http.ClientRequest in node.jsconsole.log(error.request);} else {// Something happened in setting up the request that triggered an Errorconsole.log(Error, error.message);}console.log(error.config);}); Using the validateStatus config option, you can define HTTP code(s) that should throw an error.axios.get(/user/12345, {validateStatus: function (status) {return status 500; // Resolve only if the status code is less than 500} }) Using toJSON you get an object with more information about the HTTP error.axios.get(/user/12345).catch(function (error) {console.log(error.toJSON());});五、取消请求的方式 经典的防止多次请求功能: //CancelToken 过期不推荐 You can create a cancel token using the CancelToken.source factory as shown below:const CancelToken axios.CancelToken; const source CancelToken.source();axios.get(/user/12345, {cancelToken: source.token }).catch(function (thrown) {if (axios.isCancel(thrown)) {console.log(Request canceled, thrown.message);} else {// handle error} });axios.post(/user/12345, {name: new name }, {cancelToken: source.token })// cancel the request (the message parameter is optional) source.cancel(Operation canceled by the user.); You can also create a cancel token by passing an executor function to the CancelToken constructor:const CancelToken axios.CancelToken; let cancel;axios.get(/user/12345, {cancelToken: new CancelToken(function executor(c) {// An executor function receives a cancel function as a parametercancel c;}) });// cancel the request cancel();//signal: AbortController推荐signal方式Starting from v0.22.0 Axios supports AbortController to cancel requests in fetch API way:const controller new AbortController();axios.get(/foo/bar, {signal: controller.signal }).then(function(response) {//... }); // cancel the request controller.abort() Example with a timeout using latest AbortSignal.timeout() API [nodejs 17.3]:axios.get(/foo/bar, {signal: AbortSignal.timeout(5000) //Aborts request after 5 seconds }).then(function(response) {//... }); Example with a timeout helper function:function newAbortSignal(timeoutMs) {const abortController new AbortController();setTimeout(() abortController.abort(), timeoutMs || 0);return abortController.signal; }axios.get(/foo/bar, {signal: newAbortSignal(5000) //Aborts request after 5 seconds }).then(function(response) {//... });//两种方式一起 const controller new AbortController();const CancelToken axios.CancelToken; const source CancelToken.source();axios.get(/user/12345, {cancelToken: source.token,signal: controller.signal }).catch(function (thrown) {if (axios.isCancel(thrown)) {console.log(Request canceled, thrown.message);} else {// handle error} });axios.post(/user/12345, {name: new name }, {cancelToken: source.token })// cancel the request (the message parameter is optional) source.cancel(Operation canceled by the user.); // OR controller.abort(); // the message parameter is not supported总结 axios的常用方法笔记记录完毕一定要拿到环境中去运行尝试,多看看注释都是实战总结的小提示省时省力。本文学习的内容都是为了后续实战打下坚实基础后续会自己封装一个实用的工具类。
http://www.pierceye.com/news/895318/

相关文章:

  • 网站信息备案管理系统电商网页精品欣赏网站
  • 推广公司让实名认证怎么办系统优化设置
  • 公司网站 正式上线如何创建一个软件
  • app备案查询网站上海缪斯设计公司地址
  • 旅游小网站怎样做精不做全组建网站 多少钱
  • 天津城乡住房建设厅网站网站建设观点
  • 电子商务网站建设的认识tk网站免费
  • html网页设计网站开发报告企业做的网站费入什么科目
  • 网站建设辶金手指排名十三郑州经济技术开发区教师招聘公告
  • 企业网站建设课程体会西安网站制作定制
  • 网站主题服务公司管理软件免费版
  • 网站建设主要职责六安网站建设
  • wordpress电影站主题一般做兼职在哪个网站
  • 可信网站友链怎么做网站建设行业标准
  • 济南营销网站制作公司哪家好口碑好的家装前十强
  • 公司网站开发费账务处理做图表的网站推荐
  • 网站如何做好用户体验wordpress 文章类
  • 做采集网站的方法世界四大广告公司
  • 做断桥铝窗户的网站宿州推广公司
  • 网站优化制作东莞房价一览表
  • 屏显的企业网站应该怎么做沈阳网站推广优化公司哪家好
  • 外包服务有哪些汕头seo网站建设
  • 新公司网站怎么做推广wordpress 中文 seo 插件
  • 网站建设客户分析国家企业信息公示网(广东)
  • php网站开发技术文档天津市装修公司排名榜
  • qq群优惠券里面网站怎么做的长春网站建设找源晟
  • 如何建一个公司的网站百度快速收录入口
  • 网络市场营销湘潭seo优化
  • 网站建设的模块传奇合成版2合1雷霆版手游
  • wordpress快站怎么样js网站开发视频