Skip to content

AddressPicker 地址选择器组件

此选择器用于选择地址

温馨提示

本项目参考了 uView-Plus 开源项目的组件开发方式,基于 Vue 3 和 TypeScript 实现了自定义组件。目前该组件仍处于测试阶段。
感谢 uView-Plus 开源项目及其团队成员的贡献,他们的组件开发思路为本项目提供了宝贵地参考。如果需要了解更多组件开发细节。

平台差异说明

APP(vue)H5微信小程序

基本使用示例

html
<!-- 全局使用 -->
<hy-address-picker hasInput></hy-address-picker>
<!-- 单个组件引入 -->
<HyAddressPicker hasInput></HyButton>
ts
import { HyAddressPicker } from "hy-app"

通过外部按钮打开

html
<template>
    <view>
        <hy-address-picker
            :show="show"
        ></hy-address-picker>
        <hy-button @click="show = true">打开</hy-button>
    </view>
</template>

<script setup>
    import { ref } from 'vue';

    const show = ref(false);
</script>

通过内部输入框打开

html
<template>
    <view>
        <hy-address-picker
            hasInput
            v-model="value"
        ></hy-address-picker>
    </view>
</template>

<script setup>
    import { ref } from 'vue';
    
    const value = ref(Date.now());
</script>

API

参数说明类型默认值
hasInput是否自带input输入框booleanfalse
input输入框属性集合,hasInput为true可填,详见输入框ApiHyInputProps-
show用于控制选择器的弹出与收起booleanfalse
popupMode用于控制选择器的弹出方向bottom|center|left|right|topbottom
showToolbar是否显示顶部的操作栏booleantrue
v-model绑定值string-
title顶部标题string-
separator字符串截取数组条件string" "
loading是否显示加载中状态booleanfalse
itemHeight各列中,单个选项的高度number44
cancelText取消按钮的文字string取消
confirmText确认按钮的文字string确认
cancelColor取消按钮的颜色string#909193
confirmColor确认按钮的颜色string#3c9cff
visibleItemCount每列中可见选项的数量number5
closeOnClickOverlay是否允许点击遮罩关闭选择器booleanfalse
defaultIndex各列的默认索引array-
toolbarRightSlot是否右边插槽booleanfalse
customStyle自定义输入框外部样式CSSProperties-

Events

事件名说明回调参数
close关闭选择器时触发-
confirm点击确定按钮,返回当前选择的值Array: 见上方"回调参数"部分说明
change当选择值变化时触发Array: 见上方"回调参数"部分说明
cancel点击取消按钮-

Slots

插槽名说明接收值
toolbar-right工具栏右侧内容,自定义右侧内容,因为微信小程序限制,需要同时设置:toolbarRightSlot="true"生效。-
toolbar-bottom输入框下方自定义区域-

Methods

方法名说明
setFormatter为兼容微信小程序而暴露的内部方法,见上方说明
00:46