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>

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

相关推荐
雨季66616 分钟前
Flutter 三端应用实战:OpenHarmony “极简手势轨迹球”——指尖与屏幕的诗意对话
开发语言·javascript·flutter
m0_7369191020 分钟前
编译器命令选项优化
开发语言·c++·算法
Stream_Silver21 分钟前
【Agent学习笔记1:Python调用Function Calling,阿里云API函数调用与DeepSeek API对比分析】
开发语言·python·阿里云
froginwe1122 分钟前
CSS3 多媒体查询实例
开发语言
naruto_lnq27 分钟前
C++中的工厂方法模式
开发语言·c++·算法
独自破碎E27 分钟前
LCR_019_验证回文串II
java·开发语言
一切尽在,你来28 分钟前
C++多线程教程-1.2.3 C++并发编程的平台无关性
开发语言·c++
坚持就完事了31 分钟前
Java中的一些关键字
java·开发语言
雨季66641 分钟前
Flutter 三端应用实战:OpenHarmony “专注时光盒”——在碎片洪流中守护心流的数字容器
开发语言·前端·安全·flutter·交互
新缸中之脑1 小时前
Moltbook 帖子精选
开发语言·php