Input 输入框

基础表单组件,支持多种类型输入,可自定义图标、样式等。

代码示例

				
<template>
	<zk-theme type="page" :padding="30" showBack navbarTitle="Input输入框">
		<!-- 基础用法 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="基础用法" />
			<view class="demo-content">
				<zk-input v-model="value1" placeholder="请输入内容" />
			</view>
		</zk-theme>

		<!-- 自定义样式 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="自定义样式" />
			<view class="demo-content">
				<zk-input v-model="value2" placeholder="圆角输入框" shape="circle" border="surround" />
				<view style="height: 20rpx;"></view>
				<zk-input v-model="value3" placeholder="底部边框" border="bottom" />
			</view>
		</zk-theme>

		<!-- 带图标 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="带图标的输入框" />
			<view class="demo-content">
				<zk-input v-model="value4" placeholder="搜索关键词" prefix-icon="search-line" border="surround"
					shape="circle" />
				<view style="height: 20rpx;"></view>
				<zk-input v-model="value5" placeholder="选择日期" suffix-icon="calendar-check-line" border="surround" />
			</view>
		</zk-theme>

		<!-- 可清除内容 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="可清除内容" />
			<view class="demo-content">
				<zk-input v-model="value6" placeholder="输入后显示清除图标" clearable border="surround" />
			</view>
		</zk-theme>

		<!-- 密码输入框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="密码输入框" />
			<view class="demo-content">
				<zk-input v-model="value7" type="password" placeholder="请输入密码" border="surround"
					:show-password="showPassword">
					<template #suffix>
						<view class="password-icon" @tap.stop="togglePassword">
							<zk-icon :name="showPassword ? 'eye-line' : 'eye-off-line'" :size="36"
								:color="themeColors.textSecondary" />
						</view>
					</template>
				</zk-input>
			</view>
		</zk-theme>

		<!-- 禁用状态 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="禁用状态" />
			<view class="demo-content">
				<zk-input v-model="value8" placeholder="禁用状态" disabled border="surround" />
			</view>
		</zk-theme>

		<!-- 只读状态 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="只读状态" />
			<view class="demo-content">
				<zk-input v-model="value9" placeholder="只读状态" readonly border="surround" />
			</view>
		</zk-theme>

		<!-- 最大长度 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="最大长度" />
			<view class="demo-content">
				<zk-input v-model="value10" placeholder="最多输入10个字符" :maxlength="10" border="surround" show-word-limit />
			</view>
		</zk-theme>
	</zk-theme>
</template>

<script>
	export default {
		data() {
			return {
				value1: '',
				value2: '',
				value3: '',
				value4: '',
				value5: '',
				value6: '',
				value7: '',
				value8: '禁用状态',
				value9: '只读状态',
				value10: '',
				showPassword: true
			}
		},

		computed: {
			themeColors() {
				return uni.$store.state['zk-global'].theme.current
			}
		},

		methods: {
			togglePassword() {
				this.showPassword = !this.showPassword
			}
		}
	}
</script>

<style lang="scss">
	.demo-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.password-icon {
		padding: 0 20rpx;
	}
</style>
			

API

Props 属性

参数 说明 类型 默认值
value 输入框值 string / number ''
type 输入框类型,可选值:text / password string text
border 边框样式,可选值:surround / bottom string surround
shape 形状,可选值:square / circle string square
show-password 是否显示密码 boolean false
input-align 输入框内容对齐方式 string left
font-size 字体大小,单位rpx string / number 28
placeholder 占位符 string 请输入
disabled 是否禁用 boolean false
clearable 是否可清除 boolean false
maxlength 最大输入长度,-1为不限制 number / string -1
show-word-limit 是否显示字数统计 boolean false
prefix-icon 输入框头部图标 string ''
suffix-icon 输入框尾部图标 string ''
label 输入框标签 string ''
required 是否显示必填星号 boolean false
size 输入框大小,可选值:small / default / large string default
error 是否为错误状态 boolean false

Events 事件

事件名 说明 回调参数
input 输入值改变时触发 value: string
change 输入值改变时触发 value: string
focus 输入框获得焦点时触发 event: Event
blur 输入框失去焦点时触发 event: Event
clear 点击清除按钮时触发 -
confirm 点击完成按钮时触发 event: Event

Slots 插槽

名称 说明
prefix 输入框头部内容
suffix 输入框尾部内容