uni小程序——评论、文本域、发送、键盘调起、有值后按钮变色等

一、简介

文本域默认显示一行,最多显示4行,到了4行之后不再增高。
输入值后按钮变色

二、案例演示

在这里插入图片描述

三、代码

<template>
	<view>
		<view class="plBox">
			<textarea auto-height="true" maxlength="-1" :show-confirm-bar="false" cursor-spacing="100" fixed="true"
				placeholder="评论" v-model="plValue" @input="changeDisabled"></textarea>
			<button plain="true" @click="send" :disabled="disabled">发送</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 默认禁止点击按钮
				disabled: true,
				plValue: ''
			}
		},

		onLoad() {

		},
		methods: {
			changeDisabled(e) {
				console.log(e);
				if (e.detail.value != "") {
					this.disabled = false;
				} else {
					this.disabled = true;
				}
			},
			send() {
				// console.log("点击发送", this.plValue);
				this.$emit("sendTxt", this.plValue)
			}
		}
	}
</script>

<style lang="scss">
	.plBox {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		min-height: 100rpx;
		padding: 20rpx 20rpx 20rpx 30rpx;
		box-sizing: border-box;
		background-color: #F7F7F7;
		display: flex;
		justify-content: space-between;
		align-items: center;

		textarea {
			flex: 7;
			flex-shrink: 0;
			border-radius: 15rpx;
			max-height: 140rpx !important;
			margin-right: 30rpx;
			border: none;
			background-color: #ffffff;
			padding: 20rpx;
		}

		button {
			flex: 1;
			border: 1px solid #D3D3D3;
			color: #ffffff;
			margin: 0;
			padding: 0 5rpx;
			height: 60rpx;
			line-height: 60rpx;
			font-size: 30rpx;
			background-color: #304D99;
		}
	}
</style>


网址:https://uniapp.dcloud.net.cn/component/textarea.html

auto-height="true"          //开启自动增高
:show-confirm-bar="false"   //不显示键盘上方带有”完成“按钮那一栏
cursor-spacing="100"        //指定光标与键盘的距离,不然会有遮挡
fixed="true"                //如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值