import{_ as e,r as t,G as s,aa as a,b as n,d as i,p as o,w as l,H as c,i as r,o as u,f as d,k as g,E as m,R as h}from"./index-2PZN6pGH.js";const p="https://unidemo.dcloud.net.cn/ajax/echo/text?name=uni-app";const f=e({data:()=>({title:"request",loading:!1,res:""}),methods:{sendRequest(e){switch(this.loading=!0,e){case"promise":this._requestPromise();break;case"await":this._requestAwait();break;default:this._request()}},_request(){t({url:p,dataType:"text",data:{noncestr:Date.now()},success:e=>{console.log("request success",e),s({title:"请求成功",icon:"success",mask:!0,duration:2e3}),this.res="请求结果 : "+JSON.stringify(e)},fail:e=>{console.log("request fail",e),a({content:e.errMsg,showCancel:!1})},complete:()=>{this.loading=!1}})},_requestPromise(){t({url:p,dataType:"text",data:{noncestr:Date.now()}}).then((e=>{console.log("request success",e),s({title:"请求成功",icon:"success",mask:!0,duration:2e3}),this.res="请求结果 : "+JSON.stringify(e),this.loading=!1})).catch((e=>{console.log("request fail",e),a({content:e.errMsg,showCancel:!1}),this.loading=!1}))},async _requestAwait(){let e,n;try{e=await t({url:p,dataType:"text",data:{noncestr:Date.now()}})}catch(i){n=i}n?(console.log("request fail",n),a({content:n.errMsg,showCancel:!1})):(console.log("request success",e),s({title:"请求成功",icon:"success",mask:!0,duration:2e3}),this.res="请求结果 : "+JSON.stringify(e)),this.loading=!1}}},[["render",function(e,t,s,a,p,f){const q=n(i("page-head"),c),w=r,y=m,_=h;return u(),o(w,null,{default:l((()=>[d(q,{title:p.title},null,8,["title"]),d(w,{class:"uni-padding-wrap uni-common-mt"},{default:l((()=>[d(w,{class:"uni-hello-text"},{default:l((()=>[g(" 请点击按钮向服务器发起请求 ")])),_:1}),d(w,{class:"uni-textarea uni-common-mt"},{default:l((()=>[d(y,{value:p.res},null,8,["value"])])),_:1}),d(w,{class:"uni-btn-v uni-common-mt"},{default:l((()=>[d(_,{type:"primary",onClick:f.sendRequest,loading:p.loading},{default:l((()=>[g("发起请求（Callback）")])),_:1},8,["onClick","loading"]),d(_,{type:"primary",onClick:t[0]||(t[0]=e=>f.sendRequest("promise")),loading:p.loading},{default:l((()=>[g("发起请求（Promise）")])),_:1},8,["loading"]),d(_,{type:"primary",onClick:t[1]||(t[1]=e=>f.sendRequest("await")),loading:p.loading},{default:l((()=>[g("发起请求（Async/Await）")])),_:1},8,["loading"])])),_:1})])),_:1})])),_:1})}]]);export{f as default};
