uniapp 仿微信朋友圈点击评论唤起软键盘并自定义输入框占位符

实现效果如下:

点击写笔记按钮,需要直接唤起软键盘,并且键盘上方显示详情内容,输入框内自定义占位符

 

 新建一个子组件,内容如下

<template>
	<view class="">
		<view class="input-box">
			<view class="details">{{details}}</view>
			<view class="in_bot">
				<u--textarea :height="60" :cursorSpacing="100" class="textbox" v-model="val"
				 placeholder="来写下你对此点子的想法吧~" :showConfirmBar="false" :focus="commit" border="none" @blur="blur" :placeholderStyle="placeholderStyle"></u--textarea>
				<view class="view-btn">
					<button class="but" type="primary" @tap="send">保存</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				val: '',
				placeholderStyle:{
					padding:'30rpx 0'
				}
			}
		},
		props:{
			commit: {
			  type: Boolean,
			  default: false,
			},
			details: {
			  type: String,
			  default: '',
			},
		},
		methods: {
			send() {
				this.$emit("submit", this.val)
				this.val = '';
			},
			blur(){
				this.$emit('blurCom')
			}
		}
	}
</script>
<style lang="scss" scoped>
	.input-box {
		width:686rpx;
		min-height: 210rpx;
		padding: 32rpx;
		background: #ffffff;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 15;
		.details{
			width: 686rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
		.in_bot{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 32rpx;
			.textbox{
				width: 500rpx;
				height: 110rpx;
				background: #f5f5f5;
				border-radius: 8rpx;
			}
		}
		
		.but {
			width: 130rpx !important;
			height: 64rpx;
			background: #000000;
			border-radius: 32rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: center;
			line-height: 64rpx;
			color: #ffffff;
			margin-left: 30rpx;
			
		}
	}
</style>

父组件中写笔记按钮加点击事件,并引入子组件

<view class="butt" @click="writeNote">写笔记</view>
				<view class="note_cover" v-if="focus"></view>
				<input-box v-if="focus" :details="detailInfo.idea_name" :commit="focus" @submit="submitNote" @blurCom="blurCom"></input-box>
// 点击写笔记,唤起软件盘
			writeNote(){
				this.focus = false
				this.$nextTick(()=>{
					this.focus = true
				}) //唤起软键盘
			},

最后是提交笔记和失焦事件

// 失焦,关闭软件盘
			blurCom(){
				this.focus = false
			},
			// 提交笔记
			submitNote(val){
				writeNote({
					idea_id:this.detailInfo.id,
					notes:val,
				}).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				})
				this.focus = false
			},

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用uniapp实现仿微信支付密码输入框的示例代码: ```html <template> <view class="container"> <view class="input-box"> <view v-for="(item, index) in inputList" :key="index" class="input-item" :class="{ 'input-item-active': index === currentIndex }" > <view class="input-dot" v-show="item !== ''"></view> </view> </view> <view class="keyboard"> <view class="keyboard-row" v-for="row in keyboard" :key="row"> <view class="keyboard-item" v-for="key in row" :key="key" @click="handleKeyClick(key)" > {{ key }} </view> </view> </view> </view> </template> <script> export default { data() { return { inputList: ['', '', '', '', '', ''], // 输入框列表 currentIndex: 0, // 当前输入框索引 keyboard: [ ['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['', '0', '删除'] ] // 键盘布局 }; }, methods: { handleKeyClick(key) { if (key === '删除') { if (this.currentIndex > 0) { this.currentIndex--; this.inputList[this.currentIndex] = ''; } } else { if (this.currentIndex < this.inputList.length) { this.inputList[this.currentIndex] = key; this.currentIndex++; } } } } }; </script> <style> .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .input-box { display: flex; justify-content: space-between; width: 300rpx; height: 50rpx; border: 1rpx solid #ccc; border-radius: 4rpx; overflow: hidden; } .input-item { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 24rpx; color: #333; } .input-item-active { background-color: #f5f5f5; } .input-dot { width: 10rpx; height: 10rpx; border-radius: 50%; background-color: #333; } .keyboard { margin-top: 20rpx; } .keyboard-row { display: flex; justify-content: space-between; margin-bottom: 10rpx; } .keyboard-item { display: flex; align-items: center; justify-content: center; width: 100rpx; height: 100rpx; border: 1rpx solid #ccc; border-radius: 4rpx; font-size: 32rpx; color: #333; } </style> ``` 这段代码实现了一个简单的支付密码输入框,包括自定义输入框样式和键盘布局。用户可以点击键盘上的数字输入密码,点击删除按钮可以删除已输入的密码。输入的密码会在输入框中显示为黑色圆点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值