更新记录

1.0.0(2026-06-12) 下载此版本

车牌号输入组件,支持 12 种中国车牌类型,兼容 H5、微信小程序、App。


平台兼容性

nny-car-plate-input 使用说明

uni-app Vue 3 车牌号输入组件,点击输入条弹出底部键盘,支持 12 种中国车牌类型,兼容 H5、微信小程序、App。

组件目录

components/nny-car-plate-input/
├── nny-car-plate-input.vue   # 主组件
└── plate-config.js           # 车牌类型配置与工具函数

安装方式

components/nny-car-plate-input 整个文件夹复制到目标项目的 components/ 目录下即可。

uni-app 默认开启 easycom,组件名与文件夹名一致,无需手动注册,可直接在页面中使用。

快速开始

<template>
  <nny-car-plate-input v-model="plateNumber" />
</template>

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

const plateNumber = ref('')
</script>

Props

属性 类型 默认值 说明
modelValue / v-model String '' 车牌号字符串
defaultType String 'normal' 默认车牌类型,见下方类型表
label String '车牌号码' 输入条左侧标签
placeholder String '点击输入车牌号码' 未输入时的占位文字
sheetTitle String '输入车牌号码' 弹层标题
showLabel Boolean true 是否显示标签
showTypeBar Boolean true 是否显示顶部车牌类型切换栏
showClear Boolean true 键盘底部是否显示「清空」按钮
autoClose Boolean true 填写完成后是否自动关闭弹层
disabled Boolean false 禁用,不可点击
readonly Boolean false 只读,不可点击
typeKeys Array [] 限制可选车牌类型,空数组表示全部类型

限制车牌类型示例

只显示普通车和新能源小型车:

<nny-car-plate-input
  v-model="plateNumber"
  :type-keys="['normal', 'new_energy_small']"
/>

Events

事件 参数 说明
update:modelValue value: string v-model 双向绑定
change { value, type, complete } 每次输入变化时触发
complete value: string 车牌填写完整时触发
open 弹层打开
close 弹层关闭

监听变化示例

<nny-car-plate-input
  v-model="plateNumber"
  @change="onChange"
  @complete="onComplete"
/>

<script setup>
const onChange = ({ value, type, complete }) => {
  console.log(value, type, complete)
}

const onComplete = (value) => {
  uni.showToast({ title: `录入完成:${value}`, icon: 'none' })
}
</script>

实例方法

通过 ref 可调用组件暴露的方法:

<nny-car-plate-input ref="plateRef" v-model="plateNumber" />
方法 参数 返回值 说明
open() 打开输入弹层
close() 关闭输入弹层
clear() 清空当前输入
getValue() string 获取当前车牌号
setValue(val, typeKey?) 车牌号、可选类型 设置车牌号
getType() string 获取当前类型 key
validate() { valid, message, type?, value? } 校验车牌格式
const plateRef = ref(null)

plateRef.value?.open()
plateRef.value?.setValue('京A12345', 'normal')

const result = plateRef.value?.validate()
if (!result.valid) {
  uni.showToast({ title: result.message, icon: 'none' })
}

车牌类型

key 名称 说明 位数
normal 普通 蓝牌 / 黄牌 7
new_energy_small 新能源 小型车 8
new_energy_large 新能源 大型车 8
police 警车 公安 7
coach 教练车 学车 7
trailer 挂车 拖车 7
hk_macau 港澳 出入境 7
embassy 使馆 外交 7
consulate 领馆 外交 7
emergency 应急 救援 8
wj 武警 WJ 7
military 军车 军队 7

工具函数

如需在业务代码中单独使用校验、解析等逻辑,可从 plate-config.js 导入:

import {
  PLATE_TYPES,
  validatePlate,
  parsePlateValue,
  guessPlateType,
  filterPlateTypes
} from '@/components/nny-car-plate-input/plate-config.js'

// 校验
const result = validatePlate('京A12345', 'normal')
// { valid: true, message: 'ok', type: 'normal', value: '京A12345' }

// 解析车牌字符串
const { plateType, values } = parsePlateValue('京AD12345')
函数 说明
validatePlate(value, typeKey?) 校验车牌是否合法
parsePlateValue(value, typeKey?) 解析为类型 + 各位字符数组
guessPlateType(value, fallbackKey?) 根据字符串猜测车牌类型
filterPlateTypes(keys) 按 key 数组过滤类型列表
getPlateTypeByKey(key) 根据 key 获取类型配置
getPlateString(plateType, values) 拼接车牌字符串
isPlateComplete(plateType, values) 判断是否填写完整

跨端说明

平台 实现方式
微信小程序 使用 root-portal 将弹层挂载到页面根节点,需基础库 ≥ 2.25.0
H5 / App / 其他端 组件内 fixed 定位弹层

常见问题

Q:小程序点击输入条没有反应?

确认微信基础库版本 ≥ 2.25.0(root-portal 依赖)。可在微信开发者工具中调高基础库版本后重试。

Q:如何隐藏类型切换栏?

<nny-car-plate-input v-model="plateNumber" :show-type-bar="false" />

Q:如何设置初始车牌?

直接绑定 v-model 即可,组件会自动识别类型并回填:

<nny-car-plate-input v-model="plateNumber" />

<script setup>
const plateNumber = ref('京A12345')
</script>

Q:填写完成后不想自动关弹层?

<nny-car-plate-input v-model="plateNumber" :auto-close="false" />

演示页面

本项目 pages/index/index.vue 提供了基础用法示例,可直接运行项目查看效果。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。