uniapp的多列选择器

直接粘贴~

javascript 复制代码
<template>
  <view class="container">
    <form>
      <picker mode="multiSelector" :range="multiArray" @change="onMultiChange" @columnchange="onMultiColumnChange">
        <view class="picker">
          <text>{{ multiArray[0][selectedIndex[0]] }}</text>
          <text class="iconfont icon-down"></text>
          <text>{{ multiArray[1][selectedIndex[1]] }}</text>
          <text class="iconfont icon-down"></text>
        </view>
      </picker>
    </form>
  </view>
</template>

<script>
export default {
  data() {
    return {
      multiArray: [],     // 两列联动数据
      selectedIndex: [0, 0], // 当前选中的索引,市、区
      cityList: [        // 市、区数据,仅保留广州市和深圳市
        {
          name: "广州市",
          districtList: ["荔湾区", "越秀区", "海珠区", "天河区", "白云区", "黄埔区", "番禺区", "花都区", "南沙区", "增城区", "从化区"]
        },
        {
          name: "深圳市",
          districtList: ["罗湖区", "福田区", "南山区", "宝安区", "龙岗区", "盐田区", "龙华区", "坪山区", "光明区", "大鹏新区"]
        },
		{
		  name: "xx市",
		  districtList: ["xx区", "福田区", "南山区", "宝安区", "龙岗区", "盐田区", "龙华区", "坪山区", "光明区", "大鹏新区"]
		}
      ]
    }
  },
  created() {
    // 初始化两列联动数据
    this.multiArray = [
      this.cityList.map(city => city.name), // 市列表,广州市和深圳市
      this.cityList[0].districtList // 区列表,初始化为广州市的区
    ];
  },
  methods: {
    onMultiChange(e) {
      this.selectedIndex = e.detail.value;
      // 当用户选择市时,更新区数据
      const selectedCity = this.cityList[this.selectedIndex[0]];
      this.multiArray[1] = selectedCity.districtList;
      this.selectedIndex[1] = 0;
    },
    onMultiColumnChange(e) {
      const column = e.detail.column;
      const value = e.detail.value;
      if (column === 0) {
        // 当用户改变市时,更新区数据
        const selectedCity = this.cityList[value];
        this.multiArray[1] = selectedCity.districtList;
        this.selectedIndex[1] = 0;
      }
    }
  }
}
</script>

<style>
.container {
  padding: 20px;
}
.picker {
  padding: 10px;
  background-color: #f0f0f0;
  border-radius: 5px;
  text-align: center;
  margin-bottom: 20px;
}
.iconfont {
  margin-left: 10px;
}
</style>
相关推荐
2501_9160074710 小时前
Bundle ID 注册与管理 App ID 创建指南 命名规则 权限开关与删除注意事项
android·ios·小程序·https·uni-app·iphone·webview
PedroQue9915 小时前
uni-app路由插件化:解锁高效开发新姿势
前端·uni-app
2501_9159090617 小时前
iOS 证书创建与管理 类型限制 p12 密码与云备份实操
android·ios·小程序·https·uni-app·iphone·webview
anyup17 小时前
【2026年8月】uView Pro 千星,还拿到了 GVP
前端·uni-app·github
andr_gale2 天前
02_uniapp自定义上凸效果的底部TabBar
前端·javascript·uni-app·移动端
不爱说话郭德纲2 天前
uni-app x iOS 扫码模糊怎么办?AVFoundation 灰尘级别摄像头助你超广角聚焦
前端·uni-app·app
CHB2 天前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark【Android版】
android·ios·uni-app
游戏开发爱好者84 天前
系统状态:专为iPhone和iPad设计的实时系统性能监控工具全面介绍
android·ios·小程序·uni-app·iphone·webview·ipad
2501_915909064 天前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915106325 天前
iOS 证书类型及作用说明 账号证书与签名配置的完整解读
android·ios·小程序·https·uni-app·iphone·webview