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>

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

相关推荐
雾岛听蓝几秒前
C++ 模板初阶
开发语言·c++
智算菩萨几秒前
基于spaCy的英文自然语言处理系统:低频词提取与高级文本分析
前端·javascript·easyui
小杰帅气1 分钟前
智能指针喵喵喵
开发语言·c++·算法
代码or搬砖2 分钟前
悲观锁讲解
开发语言·数据库
hudawei9963 分钟前
对比kotlin和flutter中的异步编程
开发语言·flutter·kotlin·异步·
南棱笑笑生3 分钟前
20251219给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-5.10】后解决启动不了报atf-2的问题
linux·c语言·开发语言·rockchip
deephub6 分钟前
ONNX Runtime Python 推理性能优化:8 个低延迟工程实践
开发语言·人工智能·python·神经网络·性能优化·onnx
蕨蕨学AI6 分钟前
【Wolfram语言】22 机器学习
开发语言·wolfram
百***78758 分钟前
LLaMA 4 API国内稳定接入指南:中转服务全链路实操与优化方案
开发语言·php·llama
Matlab仿真实验室9 分钟前
基于Matlab实现歌曲人声消除仿真
开发语言·matlab