2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
import{a as e,R as l,b as a,f as n,h as o,w as t,j as s,an as u,y as i,e as d,o as c,F as r,n as p,i as m,al as v}from"./index-0f0b0477.js";function f(a){const{api:n}=a,o=e(!1),t=e([]),s=e("");return l((()=>{o.value=!0,t.value=[],n().then((e=>{t.value=e.data})).finally((()=>{o.value=!1}))})),{loading:o,options:t,value:s}}const h={code:0,data:[{label:"苹果",value:1},{label:"香蕉",value:2},{label:"橘子",value:3,disabled:!0}],message:"获取 Select 数据成功"};function b(){return new Promise(((e,l)=>{setTimeout((()=>{Math.random()<.8?e(h):l(new Error("接口发生错误"))}),2e3)}))}const g={class:"app-container"},V=i("h4",null,"该示例是演示:通过 hook 自动调用 api 后拿到 Select 组件需要的数据并传递给 Select 组件",-1),S=i("h5",null,"Select 示例",-1),w=i("h5",null,"Select V2 示例(如果数据量过多,可以选择该组件)",-1),y=a({__name:"use-fetch-select",setup(e){const{loading:l,options:a,value:i}=f({api:b});return(e,f)=>{const h=d("el-option"),b=d("el-select"),y=d("el-select-v2");return c(),n("div",g,[V,S,o(b,{loading:s(l),modelValue:s(i),"onUpdate:modelValue":f[0]||(f[0]=e=>u(i)?i.value=e:null),filterable:""},{default:t((()=>[(c(!0),n(r,null,p(s(a),((e,l)=>(c(),m(h,v(e,{key:l,placeholder:"请选择"}),null,16)))),128))])),_:1},8,["loading","modelValue"]),w,o(y,{loading:s(l),modelValue:s(i),"onUpdate:modelValue":f[1]||(f[1]=e=>u(i)?i.value=e:null),options:s(a),filterable:"",placeholder:"请选择"},null,8,["loading","modelValue","options"])])}}});export{y as default};
|