@@ -125,6 +125,170 @@ const data = ref([
125125</style>
126126```
127127
128+ ## 更新列表数据
129+
130+ 列表数据如果需要更新,可以参考此示例
131+
132+ ::: details 查看更新列表数据示例
133+ ::: code-group
134+
135+ ``` html [vue]
136+ <template >
137+ <wd-search hide-cancel placeholder =" 我要去哪里?" v-model =" keyword" @search =" handleSearch" @clear =" handleClear" />
138+ <view class =" wraper" >
139+ <wd-index-bar sticky v-if =" showList.length" >
140+ <view v-for =" item in showList" :key =" item.index" >
141+ <wd-index-anchor :index =" item.index" />
142+ <wd-cell border clickable v-for =" city in item.data" :key =" city" :title =" city" @click =" handleClick(item.index, city)" ></wd-cell >
143+ </view >
144+ </wd-index-bar >
145+ </view >
146+ </template >
147+ ```
148+
149+ ``` typescript [typescript]
150+ < script lang = " ts" setup >
151+ import { useToast } from ' @/uni_modules/wot-design-uni'
152+ import { nextTick , onMounted , ref } from ' vue'
153+ const { show : showToast } = useToast ()
154+
155+ onMounted (() => {
156+ handleSearch ()
157+ })
158+
159+ const keyword = ref (' ' )
160+
161+ const showList = ref <any >([])
162+
163+ const indexList = [
164+ {
165+ index: ' A' ,
166+ data: [' 阿坝' , ' 阿拉善' , ' 阿里' , ' 安康' , ' 安庆' , ' 鞍山' , ' 安顺' , ' 安阳' , ' 澳门' ]
167+ },
168+ {
169+ index: ' B' ,
170+ data: [' 北京' , ' 白银' , ' 保定' , ' 宝鸡' , ' 保山' , ' 包头' , ' 巴中' , ' 北海' , ' 蚌埠' , ' 本溪' , ' 毕节' , ' 滨州' , ' 百色' , ' 亳州' ]
171+ },
172+ {
173+ index: ' C' ,
174+ data: [
175+ ' 重庆' ,
176+ ' 成都' ,
177+ ' 长沙' ,
178+ ' 长春' ,
179+ ' 沧州' ,
180+ ' 常德' ,
181+ ' 昌都' ,
182+ ' 长治' ,
183+ ' 常州' ,
184+ ' 巢湖' ,
185+ ' 潮州' ,
186+ ' 承德' ,
187+ ' 郴州' ,
188+ ' 赤峰' ,
189+ ' 池州' ,
190+ ' 崇左' ,
191+ ' 楚雄' ,
192+ ' 滁州' ,
193+ ' 朝阳'
194+ ]
195+ },
196+ {
197+ index: ' D' ,
198+ data: [' 大连' , ' 东莞' , ' 大理' , ' 丹东' , ' 大庆' , ' 大同' , ' 大兴安岭' , ' 德宏' , ' 德阳' , ' 德州' , ' 定西' , ' 迪庆' , ' 东营' ]
199+ },
200+ {
201+ index: ' E' ,
202+ data: [' 鄂尔多斯' , ' 恩施' , ' 鄂州' ]
203+ },
204+ {
205+ index: ' F' ,
206+ data: [' 福州' , ' 防城港' , ' 佛山' , ' 抚顺' , ' 抚州' , ' 阜新' , ' 阜阳' ]
207+ },
208+ {
209+ index: ' G' ,
210+ data: [' 广州' , ' 桂林' , ' 贵阳' , ' 甘南' , ' 赣州' , ' 甘孜' , ' 广安' , ' 广元' , ' 贵港' , ' 果洛' ]
211+ },
212+ {
213+ index: ' H' ,
214+ data: [
215+ ' 杭州' ,
216+ ' 哈尔滨' ,
217+ ' 合肥' ,
218+ ' 海口' ,
219+ ' 呼和浩特' ,
220+ ' 海北' ,
221+ ' 海东' ,
222+ ' 海南' ,
223+ ' 海西' ,
224+ ' 邯郸' ,
225+ ' 汉中' ,
226+ ' 鹤壁' ,
227+ ' 河池' ,
228+ ' 鹤岗' ,
229+ ' 黑河' ,
230+ ' 衡水' ,
231+ ' 衡阳' ,
232+ ' 河源' ,
233+ ' 贺州' ,
234+ ' 红河' ,
235+ ' 淮安' ,
236+ ' 淮北' ,
237+ ' 怀化' ,
238+ ' 淮南' ,
239+ ' 黄冈' ,
240+ ' 黄南' ,
241+ ' 黄山' ,
242+ ' 黄石' ,
243+ ' 惠州' ,
244+ ' 葫芦岛' ,
245+ ' 呼伦贝尔' ,
246+ ' 湖州' ,
247+ ' 菏泽'
248+ ]
249+ }
250+ ]
251+
252+ function handleClick(index : string , city : string ) {
253+ showToast (` 当前点击项:${index },城市:${city } ` )
254+ }
255+
256+ function handleSearch() {
257+ showList .value = []
258+ nextTick (() => {
259+ if (keyword .value ) {
260+ showList .value = indexList .filter ((item ) => {
261+ return item .data .some ((city ) => {
262+ return city .includes (keyword .value )
263+ })
264+ })
265+ } else {
266+ showList .value = indexList
267+ }
268+ })
269+
270+ // 筛选indexList项中data包含keyword的项
271+ }
272+
273+ function handleClear() {
274+ keyword .value = ' '
275+ handleSearch ()
276+ }
277+ < / script >
278+ ```
279+
280+ ``` css [css]
281+ .wraper {
282+ height : calc (100vh - var (--window-top ));
283+ height : calc (100vh - var (--window-top ) - constant(safe-area-inset-bottom));
284+ height : calc (100vh - var (--window-top ) - env(safe-area-inset-bottom));
285+ }
286+ ```
287+
288+ :::
289+
290+
291+
128292## Attributes
129293
130294| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
0 commit comments