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>

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

相关推荐
输出输入几秒前
前端核心技术
开发语言·前端
加油,小猿猿1 分钟前
Java开发日志-双数据库事务问题
java·开发语言·数据库
薛定谔的猫喵喵7 分钟前
天然气压力能利用系统综合性评价平台:基于Python和PyQt5的AHP与模糊综合评价集成应用
开发语言·python·qt
独好紫罗兰19 分钟前
对python的再认识-基于数据结构进行-a004-列表-实用事务
开发语言·数据结构·python
gjxDaniel20 分钟前
Objective-C编程语言入门与常见问题
开发语言·objective-c
choke23331 分钟前
[特殊字符] Python异常处理
开发语言·python
云中飞鸿31 分钟前
linux中qt安装
开发语言·qt
少控科技1 小时前
QT第6个程序 - 网页内容摘取
开发语言·qt
darkb1rd1 小时前
八、PHP SAPI与运行环境差异
开发语言·网络安全·php·webshell
历程里程碑1 小时前
Linux20 : IO
linux·c语言·开发语言·数据结构·c++·算法