uniapp 城市选择插件

uniapp城市选择插件

如上图
地址

完整demo

复制代码
<template>
    <view>
        <city-select
            @cityClick="cityClick"
            :formatName="formatName"
            :activeCity="activeCity"
            :hotCity="hotCity"
            :obtainCitys="obtainCitys"
            :isSearch="true"
            ref="citys"
        ></city-select>
    </view>
</template>

<script>
import citys from './citys.js'
console.log(citys.length)
import citySelect from '@/components/city-select/city-select.vue'
export default {
    data() {
        return {
            //需要构建索引参数的名称(注意:传递的对象里面必须要有这个名称的参数)
            formatName: 'title',
            //当前城市
            activeCity: {
                id: 1,
                title: '南京市'
            },
            //热门城市
            hotCity: [
                {
                    id: 0,
                    title: '南京市'
                },
                {
                    id: 1,
                    title: '南京市'
                }
            ],
            //显示的城市数据
            obtainCitys: [
                {
                    id: 0,
                    title: '南京'
                },
                {
                    id: 1,
                    title: '北京'
                },
                {
                    id: 2,
                    title: '天津'
                },
                {
                    id: 3,
                    title: '东京'
                }
            ]
        }
    },
    components: {
        citySelect
    },
    onLoad() {
        //动态更新数据
        setTimeout(() => {
            //修改需要构建索引参数的名称
            this.formatName = 'cityName'
            //修改当前城市
            this.activeCity = {
                cityName: '南京',
                cityCode: 110100
            }
            //修改热门城市
            this.hotCity = [
                {
                    cityName: '南京',
                    cityCode: 110100
                },
                {
                    cityName: '北京',
                    cityCode: 110102
                }
            ]
            //修改构建索引数据
            this.obtainCitys = citys
            uni.showToast({
                icon: 'none',
                title: '更新数据成功',
                // #ifdef MP-WEIXIN
                duration: 3000,
                // #endif
                mask: true
            })
        }, 5000)
    },
    methods: {
        cityClick(item) {
            uni.showToast({
                icon: 'none',
                title: 'item: ' + JSON.stringify(item),
                // #ifdef MP-WEIXIN
                duration: 3000,
                // #endif
                mask: true
            })
        }
    }
}
</script>

<style></style>

根据地区中的首字母进行排序,然后在显示出来

相关推荐
无心水20 小时前
【Python实战进阶】5、Python字符串终极指南:从基础到高性能处理的完整秘籍
开发语言·网络·python·字符串·unicode·python实战进阶·python工业化实战进阶
FinelyYang21 小时前
uniapp+unipush2.0+WebRTC实现h5一对一视频通话
uni-app·音视频·webrtc
4***149021 小时前
Rust系统工具开发实践指南
开发语言·后端·rust
心随雨下21 小时前
typescript中Triple-Slash Directives如何使用
前端·javascript·typescript
2501_9409439121 小时前
体系课\ Python Web全栈工程师
开发语言·前端·python
低保和光头哪个先来21 小时前
场景2:Vue Router 中 query 与 params 的区别
前端·javascript·vue.js·前端框架
rafael(一只小鱼)21 小时前
AI运维开发平台学习
java·开发语言
b***748821 小时前
C++在系统中的内存对齐
开发语言·c++
散峰而望21 小时前
C++数组(三)(算法竞赛)
开发语言·c++·算法·github
q***95221 天前
SpringMVC 请求参数接收
前端·javascript·算法