mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-26 06:14:08 +08:00
1 line
3.4 KiB
JavaScript
1 line
3.4 KiB
JavaScript
import{_n as e,gn as t,hn as n}from"./replaceable-DW6s2lkT.js";import{L as r,Y as i}from"./toString-BWDzaUQG.js";import{n as a,t as o}from"./axios-BycRQuV2.js";import{t as s}from"./Button-vr5e8LJV.js";import{t as c}from"./Card-D38P0NK6.js";import{$ as l,S as u,st as d}from"./index-rJvBcjbC.js";import{t as f}from"./Input-CcCbIWFY.js";var p=e=>a({url:`https://www.tianqiapi.com/api?version=v9&appid=23035354&appsecret=8YvlPNrz&city=${e}`,method:`get`}),m=()=>a({url:`https://jsonplaceholder.typicode.com/todos/1`,method:`get`}),h=e({name:`RAxios`,setup(){let e=r({weatherData:[],inputCityValue:null,throttleDemoInputValue:null,debounceDemoInputValue:null,weatherDemoInputValue:null}),{data:t,loading:n,run:a}=u(m,{throttleWait:1e3,manual:!0}),{data:s,loading:c,run:l}=u(m,{debounceWait:1e3,manual:!0}),{data:d,loading:f,run:h}=u(p,{throttleWait:1e3,manual:!0}),{data:g,loading:_,run:v}=o({url:`https://jsonplaceholder.typicode.com/todos/1`,method:`get`,cancelConfig:{cancel:!0}},{manual:!0,onError:()=>{window.$message.error(`接口出现异常`)}});return{...i(e),throttleDemoValue:t,throttleDemoLoading:n,throttleDemoRun:a,debounceDemoValue:s,debounceDemoLoading:c,debounceDemoRun:l,weatherDemoValue:d,weatherDemoLoading:f,weatherDemoRun:h,demoData:g,demoLoading:_,demoRun:v}},render(){return t(l,null,{default:()=>[t(d,{vertical:!0},{default:()=>[t(`h1`,null,[n(`请求`)]),t(c,null,{default:()=>[t(`h2`,null,[n(`useRequest`)]),t(`p`,null,[n(`支持配置化请求数据`)]),t(`h2`,null,[n(`useHookPlusRequest`)]),t(`p`,null,[n(`支持包裹一个拥有 promise 状态的异步函数,可以用来包裹一个 axios 请求返回值方法`)])]}),t(`h1`,null,[n(`使用 useRequest 获取`)]),t(c,{title:`请求函数`},{default:()=>[t(`h3`,null,[n(`1.基于 axios 封装,能够自动取消连续请求,避免重复渲染造成问题`)]),t(`h3`,null,[n(`2.打开控制台 => 网络 => 使用低速3g网络 => 查看控制台被取消的请求`)]),t(`h3`,null,[n(`3.详情请查看文档`)])]}),t(c,{title:`useRequest示例(手动触发)`},{default:()=>[t(d,{vertical:!0},{default:()=>[t(s,{onClick:this.demoRun.bind(this)},{default:()=>[n(`获取数据`)]}),t(`h3`,null,[n(`结果:\xA0`),this.demoLoading?`获取中...`:this.demoData?.title])]})]}),t(`h1`,null,[n(`使用 useHookPlusRequest 获取`)]),t(c,{title:`节流`},{default:()=>[t(d,{vertical:!0},{default:()=>[t(f,{value:this.throttleDemoInputValue,"onUpdate:value":e=>this.throttleDemoInputValue=e,onUpdateValue:()=>{this.throttleDemoRun()}},null),t(`h3`,null,[n(`不论触发多少次,一秒钟之内仅会触发一次`)]),t(`h3`,null,[n(`当前状态:\xA0`),this.throttleDemoLoading?`获取中...`:`获取成功!!!`])]})]}),t(c,{title:`防抖`},{default:()=>[t(d,{vertical:!0},{default:()=>[t(f,{value:this.debounceDemoInputValue,"onUpdate:value":e=>this.debounceDemoInputValue=e,onUpdateValue:()=>{this.debounceDemoRun()}},null),t(`h3`,null,[n(`一秒后才会执行,如果中途重新请求,则会重新计时`)]),t(`h3`,null,[n(`当前状态:\xA0`),this.debounceDemoLoading?`获取中...`:`获取成功!!!`])]})]}),t(c,{title:`获取气候`},{default:()=>[t(d,{vertical:!0},{default:()=>[t(f,{value:this.weatherDemoInputValue,"onUpdate:value":e=>this.weatherDemoInputValue=e,onUpdateValue:e=>{this.weatherDemoRun(e)}},null),t(`h3`,null,[n(`该示例演示了如何根据动态值获取数据`)]),t(`h3`,null,[n(`当前状态:\xA0`),this.weatherDemoLoading?`获取中...`:`获取成功!!!`])]})]})]})]})}});export{h as default}; |