Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
e6f8801c
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e6f8801c
编写于
8月 16, 2023
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新input示例
上级
ff275360
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
301 addition
and
298 deletion
+301
-298
pages/component/input/input.uvue
pages/component/input/input.uvue
+301
-298
未找到文件。
pages/component/input/input.uvue
浏览文件 @
e6f8801c
<template>
<template>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<scroll-view style="flex: 1">
<!-- #endif -->
<!-- #endif -->
<view class="nvue-page-root">
<page-head :title="title"></page-head>
<page-head :title="title"></page-head>
<view class="uni-common-mt uni-padding-wrap">
<view class="uni-common-mt">
<view>
<view class="uni-form-item uni-column">
<view class="uni-title">
<view class="title"
<text class="uni-title-text">设置输入框的初始内容</text>
><text class="uni-form-item__title">可自动聚焦的 input</text></view
</view>
>
<view class="uni-input-wrapper">
<view class="uni-input-wrapper">
<input class="uni-input" value="hello uni-app x" />
<input
</view>
class="uni-input"
</view>
:focus="true"
placeholder="自动获得焦点"
<view>
ref="input"
<view class="uni-title">
/>
<text class="uni-title-text">type取值(不同输入法表现可能不一致)</text>
</view>
</view>
</view>
<view class="uni-input-wrapper">
<!-- #ifdef APP-PLUS -->
<input class="uni-input" type="text" placeholder="文本输入键盘" />
<!-- <view v-if="platform==='ios'&&!isNvue" class="uni-form-item uni-column">
</view>
<view class="title"><text class="uni-form-item__title">隐藏 iOS 软键盘上的导航条</text></view>
<view class="uni-input-wrapper">
<view class="uni-input-wrapper">
<input class="uni-input" type="number" placeholder="数字输入键盘" />
<input class="uni-input" placeholder="触摸其他地方收起键盘" @focus="onFocus" @blur="onBlur" />
</view>
</view>
<view class="uni-input-wrapper">
</view> -->
<input class="uni-input" type="digit" placeholder="带小数点的数字输入键盘" />
<!-- #endif -->
</view>
<view class="uni-form-item uni-column">
<view class="uni-input-wrapper">
<view class="title"
<input class="uni-input" type="tel" placeholder="电话输入键盘" />
><text class="uni-form-item__title"
</view>
>键盘右下角按钮显示为搜索</text
</view>
></view
>
<view>
<view class="uni-input-wrapper">
<view class="uni-title">
<input
<text class="uni-title-text">密码输入框</text>
class="uni-input"
</view>
confirmType="search"
<view class="uni-input-wrapper">
placeholder="键盘右下角按钮显示为搜索"
<input class="uni-input" :password="true" />
/>
</view>
</view>
</view>
</view>
<!-- #ifndef H5 -->
<view>
<view class="uni-form-item uni-column">
<view class="uni-title">
<view class="title"
<text class="uni-title-text">占位符样式</text>
><text class="uni-form-item__title"
</view>
>键盘右下角按钮显示为发送</text
<view class="uni-input-wrapper">
></view
<input class="uni-input" placeholder-style="color:red" placeholder="占位符文字颜色为红色" />
>
</view>
<view class="uni-input-wrapper">
<view class="uni-input-wrapper">
<input
<input class="uni-input" placeholder-class="uni-input-placeholder-class" placeholder="占位符背景色为绿色" />
class="uni-input"
</view>
confirmType="send"
</view>
placeholder="键盘右下角按钮显示为发送"
/>
<view>
</view>
<view class="uni-title">
</view>
<text class="uni-title-text">设置禁用输入框</text>
<!-- #endif -->
</view>
<view class="uni-form-item uni-column">
<view class="uni-input-wrapper">
<view class="title"
<input class="uni-input" :disabled="true" />
><text class="uni-form-item__title"
</view>
>控制最大输入长度的 input</text
</view>
></view
>
<view>
<view class="uni-input-wrapper">
<view class="uni-title">
<input
<text class="uni-title-text">设置最大输入长度</text>
class="uni-input"
</view>
:maxlength="10"
<view class="uni-input-wrapper">
placeholder="最大输入长度为10"
<input class="uni-input" :maxlength="10" placeholder="最大输入长度为10" />
/>
</view>
</view>
</view>
</view>
<view class="uni-form-item uni-column">
<view>
<view class="title"
<view class="uni-title">
><text class="uni-form-item__title"
<text class="uni-title-text">设置光标与键盘的距离</text>
>实时获取输入值:{{ inputValue }}</text
</view>
></view
<view class="uni-input-wrapper">
>
<input class="uni-input" :cursor-spacing="1000" placeholder="光标与键盘的距离为1000px" />
<view class="uni-input-wrapper">
</view>
<input
</view>
class="uni-input"
@input="onKeyInput"
<view>
placeholder="输入同步到view中"
<view class="uni-title">
/>
<text class="uni-title-text">自动获取焦点</text>
</view>
</view>
</view>
<view class="uni-input-wrapper">
<view class="uni-form-item uni-column">
<input class="uni-input" :focus="true" />
<view class="title"
</view>
><text class="uni-form-item__title">控制输入的 input</text></view
</view>
>
<view class="uni-input-wrapper">
<view>
<input
<view class="uni-title">
class="uni-input"
<text class="uni-title-text">confirm-type取值(不同输入法表现可能不一致)</text>
@input="replaceInput"
</view>
:value="changeValue"
<view class="uni-input-wrapper">
placeholder="连续的两个1会变成2"
<input class="uni-input" confirmType="send" placeholder="键盘右下角按钮显示为发送" />
/>
</view>
</view>
<view class="uni-input-wrapper">
</view>
<input class="uni-input" confirmType="search" placeholder="键盘右下角按钮显示为搜索" />
<!-- #ifndef MP-BAIDU -->
</view>
<!-- <view class="uni-form-item uni-column">
<view class="uni-input-wrapper">
<view class="title"><text class="uni-form-item__title">控制键盘的 input</text></view>
<input class="uni-input" confirmType="next" placeholder="键盘右下角按钮显示为下一个" />
<view class="uni-input-wrapper">
</view>
<input class="uni-input" ref="input1" @input="hideKeyboard" placeholder="输入123自动收起键盘" />
<view class="uni-input-wrapper">
</view>
<input class="uni-input" confirmType="go" placeholder="键盘右下角按钮显示为前往" />
</view> -->
</view>
<!-- #endif -->
<view class="uni-input-wrapper">
<view class="uni-form-item uni-column">
<input class="uni-input" confirmType="done" placeholder="键盘右下角按钮显示为完成" />
<view class="title"
</view>
><text class="uni-form-item__title">数字输入的 input</text></view
</view>
>
<view class="uni-input-wrapper">
<view>
<input
<view class="uni-title">
class="uni-input"
<text class="uni-title-text">点击键盘右下角按钮时保持键盘不收起</text>
type="number"
</view>
placeholder="这是一个数字输入框"
<view class="uni-input-wrapper">
/>
<input class="uni-input" :confirm-hold="true" />
</view>
</view>
</view>
</view>
<view class="uni-form-item uni-column">
<view class="title"
<view>
><text class="uni-form-item__title">密码输入的 input</text></view
<view class="uni-title" @click="setCursor(4)">
>
<text class="uni-title-text">设置输入框聚焦时光标的位置(点击生效)</text>
<view class="uni-input-wrapper">
</view>
<input
<view class="uni-input-wrapper">
class="uni-input"
<input ref="input" class="uni-input" value="0123456789" :cursor="cursor" />
:password="true"
</view>
type="text"
</view>
placeholder="这是一个密码输入框"
/>
<view>
</view>
<view class="uni-title" @click="setSelection(0, 4)">
</view>
<text class="uni-title-text">设置输入框聚焦时光标的起始位置和结束位置(点击生效)</text>
<view class="uni-form-item uni-column">
</view>
<view class="title"
<view class="uni-input-wrapper">
><text class="uni-form-item__title">带小数点的 input</text></view
<input ref="input2" class="uni-input" value="0123456789" :selection-start="selectionStart"
>
:selection-end="selectionEnd" />
<view class="uni-input-wrapper">
</view>
<input
</view>
class="uni-input"
type="digit"
<view>
placeholder="带小数点的数字键盘"
<view class="uni-title">
/>
<text class="uni-title-text">键盘弹起时,自动上推页面</text>
</view>
</view>
</view>
<view class="uni-input-wrapper">
<!-- <view class="uni-form-item uni-column">
<input class="uni-input" :adjust-position="true" />
<view class="title"><text class="uni-form-item__title">身份证输入的 input</text></view>
</view>
<view class="uni-input-wrapper">
</view>
<input class="uni-input" type="idcard" placeholder="身份证输入键盘" /> </view>
</view> -->
<view>
<view class="uni-form-item uni-column">
<view class="uni-title">
<view class="title"
<text class="uni-title-text">input事件</text>
><text class="uni-form-item__title"
<text class="uni-subtitle-text" v-if="inputEventDetail">{{inputEventDetail}}</text>
>控制占位符颜色的 input</text
</view>
></view
<view class="uni-input-wrapper">
>
<input class="uni-input" @input="onInput" />
<view class="uni-input-wrapper">
</view>
<input
</view>
class="uni-input"
placeholder-style="color:#F76260"
<view>
placeholder="占位符字体是红色的"
<view class="uni-title">
/>
<text class="uni-title-text">focus事件和blur事件</text>
</view>
<text class="uni-subtitle-text" v-if="focusAndBlurEventDetail">{{focusAndBlurEventDetail}}</text>
</view>
</view>
<view class="uni-form-item uni-column">
<view class="uni-input-wrapper">
<view class="title"
<input class="uni-input" @focus="onFocus" @blur="onBlur" />
><text class="uni-form-item__title">带清除按钮的输入框</text></view
</view>
>
</view>
<view class="uni-input-wrapper">
<input
<view>
class="uni-input"
<view class="uni-title">
placeholder="带清除按钮的输入框"
<text class="uni-title-text">confirm事件</text>
:value="inputClearValue"
<text class="uni-subtitle-text" v-if="confirmEventDetail">{{confirmEventDetail}}</text>
@input="clearInput"
</view>
/>
<view class="uni-input-wrapper">
<image
<input class="uni-input" @confirm="onConfirm" />
class="uni-icon"
</view>
src="/static/icons/clear.png"
</view>
v-if="showClearIcon"
@click="clearIcon"
<view>
></image>
<view class="uni-title">
</view>
<text class="uni-title-text">keyboardheightchange事件</text>
</view>
<text class="uni-subtitle-text"
<view class="uni-form-item uni-column">
v-if="keyboardHeightChangeEventDetail">{{keyboardHeightChangeEventDetail}}</text>
<view class="title"
</view>
><text class="uni-form-item__title">可查看密码的输入框</text></view
<view class="uni-input-wrapper">
>
<input class="uni-input" @keyboardheightchange="onKeyborardHeightChange" />
<view class="uni-input-wrapper">
</view>
<input
</view>
class="uni-input"
placeholder="请输入密码"
<view>
:password="showPassword"
<view class="uni-title">
/>
<text class="uni-title-text">带清除按钮的输入框</text>
<image
</view>
class="uni-icon"
<view class="uni-input-wrapper">
:src="
<input class="uni-input" placeholder="带清除按钮的输入框" :value="inputClearValue" @input="clearInput" />
!showPassword
<image class="uni-icon" src="/static/icons/clear.png" v-if="showClearIcon" @click="clearIcon">
? '/static/icons/eye-active.png'
</image>
: '/static/icons/eye.png'
</view>
"
</view>
@click="changePassword"
></image>
<view>
</view>
<view class="uni-title">
</view>
<text class="uni-title-text">可查看密码的输入框</text>
</view>
</view>
</view>
<view class="uni-input-wrapper">
<!-- #ifdef APP -->
<input class="uni-input" placeholder="请输入密码" :password="showPassword" />
</scroll-view>
<image class="uni-icon"
<!-- #endif -->
:src="!showPassword ? '/static/icons/eye-active.png' : '/static/icons/eye.png'"
@click="changePassword"></image>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
</template>
<script lang="ts">
<script lang="ts">
export default {
export default {
data() {
data() {
return {
return {
title: 'input',
title: 'input',
focus: false,
showClearIcon: false,
inputValue: '',
inputClearValue: '',
showClearIcon: false,
showPassword: true,
inputClearValue: '',
cursor: -1,
changeValue: '',
selectionStart: -1,
showPassword: true,
selectionEnd: -1,
}
inputEventDetail: '',
},
focusAndBlurEventDetail: '',
onReady() {
confirmEventDetail: '',
// TODO auto focus
keyboardHeightChangeEventDetail: ''
// (this.$refs['input'] as INode).focus();
}
},
},
methods: {
methods: {
onKeyInput: function (event: InputEvent) {
setCursor: function (cursor : number) {
this.inputValue = event.detail.value
(this.$refs['input'] as INode).focus();
},
this.cursor = cursor;
replaceInput: function (event: InputEvent) {
},
var value = event.detail.value
setSelection: function (selectionStart : number, selectionEnd : number) {
if (value == '11') {
(this.$refs['input2'] as INode).focus();
this.changeValue = '2'
this.selectionStart = selectionStart;
}
this.selectionEnd = selectionEnd;
},
},
clearInput: function (event: InputEvent) {
clearInput: function (event : InputEvent) {
this.inputClearValue = event.detail.value
this.inputClearValue = event.detail.value
if (event.detail.value.length > 0) {
if (event.detail.value.length > 0) {
this.showClearIcon = true
this.showClearIcon = true
} else {
} else {
this.showClearIcon = false
this.showClearIcon = false
}
}
},
},
clearIcon: function () {
clearIcon: function () {
this.inputClearValue = ''
this.inputClearValue = ''
this.showClearIcon = false
this.showClearIcon = false
},
},
changePassword: function () {
changePassword: function () {
this.showPassword = !this.showPassword
this.showPassword = !this.showPassword
},
},
// hideKeyboard: function(event: InputEvent) {
onInput: function (event : InputEvent) {
// if (event.detail.value === '123') {
console.log("键盘输入", JSON.stringify(event.detail));
// uni.hideKeyboard();
this.inputEventDetail = JSON.stringify(event.detail)
// }
},
// },
onFocus: function (event : InputFocusEvent) {
// onFocus() {
console.log("输入框聚焦", JSON.stringify(event.detail));
// this.$mp.page.$getAppWebview().setStyle({
this.focusAndBlurEventDetail = JSON.stringify(event.detail);
// softinputNavBar: 'none'
},
// })
onBlur: function (event : InputBlurEvent) {
// },
console.log("输入框失去焦点", JSON.stringify(event.detail));
// onBlur() {
this.focusAndBlurEventDetail = JSON.stringify(event.detail);
// this.$mp.page.$getAppWebview().setStyle({
},
// softinputNavBar: 'auto'
onConfirm: function (event : InputConfirmEvent) {
// })
console.log("点击完成按钮", JSON.stringify(event.detail));
// }
this.confirmEventDetail = JSON.stringify(event.detail);
},
},
}
onKeyborardHeightChange: function (event : InputKeyboardHeightChangeEvent) {
console.log("键盘高度发生变化", JSON.stringify(event.detail));
this.keyboardHeightChangeEventDetail = JSON.stringify(event.detail);
}
}
}
</script>
</script>
<style scoped>
<style scoped>
.nvue-page-root {
.uni-input-wrapper {
background-color: #f8f8f8;
display: flex;
padding-bottom: 20px;
padding: 8px 13px;
}
margin: 10rpx 0;
flex-direction: row;
.title {
flex-wrap: nowrap;
padding: 5px 13px;
background-color: #ffffff;
}
}
.uni-form-item__title {
font-size: 16px;
line-height: 24px;
}
.uni-input-wrapper {
.uni-input {
display: flex;
height: 28px;
padding: 8px 13px;
line-height: 28px;
flex-direction: row;
font-size: 15px;
flex-wrap: nowrap;
padding: 0px;
background-color: #ffffff;
flex: 1;
}
background-color: #ffffff;
}
.uni-input {
.uni-icon {
height: 28px;
width: 24px;
line-height: 28px;
height: 24px;
font-size: 15px;
}
padding: 0px;
flex: 1;
background-color: #ffffff;
}
.uni-icon {
.uni-input-placeholder-class {
width: 24px;
background-color: green;
height: 24px;
}
}
</style>
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录