vue实现textarea框,文字高度自适应,https://blog.csdn.net/qq_38128179/article/details/103591717

下面是两种方式,注释掉的是一种,不可以输入字数超出100字,另一种是可以超出,超出字数变红提示

<template><div class="textarea"><!-- <Fieldv-model="memo"rows="5":placeholder="placeholderText"type="textarea":maxlength="maxlength"show-word-limitborder@focus="onInput"ref="memo":value="parameter.text"@input="inputHandler":autosize="true"/> --><textareastyle="width: 100%"cols="40"rows="5":placeholder="placeholderText":minlength="maxlength"v-model="memo"ref="form__input"id="textarea"v-on:keyup="content()":onFocus="focus()":onBlur="blur()"@input="handleInput"></textarea><p class="textNum"><span :class="conterNum > maxlength ? 'conter_Num' : ''">{{conterNum}}</span><span>/{{ maxlength }}</span></p></div>
</template><script>
import { Field, Toast } from 'vant';
import 'vant/lib/index.less';
import { resize } from '@/utils/resize';export default {name: 'Demo',components: {Field, Toast},data () {return {notNumbers: false,conterNum: 0,maxlength: 100,memo: '',placeholderText: "请输入您的问题",parameter: {text: ""}}},created () {resize()},mounted () {// this.$refs.form__input.focus()//一进页面弹出键盘},methods: {//根据输入长度高度自适应handleInput (e) {e.target.style.height = 'auto';e.target.style.height = e.target.scrollHeight + 'px';},content () {this.notNumbers = falsethis.conterNum = this.memo.length;this.parameter.text = this.memo},focus () {this.conterNum = this.memo.length;this.parameter.text = this.memo},blur () {this.conterNum = this.memo.length;this.parameter.text = this.memo},// onInput () {//   this.$refs.memo.focus();// },// inputHandler (value) {//   value = this.max > 0 ? Math.min(value, this.max || 0) : value//   this.$emit('input', value)//   this.parameter.text = value//   if (value.length >= this.maxlength) {//     Toast(`最多输入${this.maxlength}字`)//     this.$ZhiYue.toast(`最多输入${this.maxlength}字`)//   }// },},
}
</script>
<style scoped lang="scss">
* {margin: 0;padding: 0;
}.textarea {margin: 0.2rem 0.32rem 0 0.32rem;
}.input {height: 0.9rem;border: none !important;border-radius: 0.08rem;outline: none;font-size: 15px;border-radius: 0.1rem;flex: 7;
}
::v-deep .van-cell {font-size: 0.32rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;text-align: left;color: #cccccc;
}
::v-deep .van-field__control {font-size: 0.3rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;text-align: left;color: #333333;line-height: 0.44rem;
}input::-webkit-input-placeholder {font-size: 0.3rem;line-height: 0.3rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;color: #cccccc;
}
#textarea {border: 1px solid #f3f3f3;font-size: 0.3rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;text-align: left;color: #333333;outline: none;resize: none;border: none;
}
textarea::-webkit-input-placeholder {font-size: 0.32rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;text-align: left;color: #cccccc;
}
.textNum {position: absolute;right: 0.32rem;font-size: 0.26rem;font-family: PingFangSC, PingFangSC-Regular;font-weight: 400;text-align: right;color: #999999;
}
.conter_Num {color: #ff3e3e;
}
</style>

vue实现textarea框,文字高度自适应相关推荐

  1. div模拟textarea文本框,输入文字高度自适应,且实现字数统计和限制

    需求: 文本框可根据输入内容高度自适应,不带滚动条,高度可变的那种,我搜索了很多,发现textarea无法实现我的需求,scrollHeigh这个无法获取实际内容的高度(我用的是那种简单的,可能我写的 ...

  2. textarea如何实现高度自适应?

    文章来源:http://blog.csdn.net/tianyitianyi1/article/details/49923069 转自:http://www.xuanfengge.com/textar ...

  3. html textarea文本域高度自适应

    1.可直接在 菜鸟教程网站测试页面中测试 <!DOCTYPE html> <html> <head><meta charset="utf-8&quo ...

  4. java textarea 大小_textarea高度自适应的两种方案

    阅读全文你将获得以下解决方案. 点击长文本编辑textarea,自动获得焦点 随着输入值自动伸缩高度 可复制添加信息 可粘贴文本 可粘贴图片 以下实例代码执行环境为Chrome80 方案一 HTML5 ...

  5. html textarea a 整体,html textarea文本域高度自适应

    1.可直接在 菜鸟教程网站测试页面中测试 菜鸟教程(runoob.com) id="symptomTxt" οninput="autoTextAreaHeight(thi ...

  6. div模拟textarea文本域轻松实现高度自适应——张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com 本文地址: http://www.zhangxinxu.com/wordpress/?p=1362 一.关于t ...

  7. QComboBox下拉框文字如何在字体变大之后自适应高度

    一.简述 一般我们给QComboBox设置完字体之后,在显示上并没有什么问题如下图. a.正常状态 由于程序在最大化的时候,因为主窗口尺寸变大,需要整体改变所有控件的尺寸,文字的大小,所以在窗口最大化 ...

  8. vue+element弹窗可拖拽拉伸和弹窗内table高度自适应

    需求是这样的:需要将目前的el-dialog弹窗都改成可拉伸和拖拽的.并且做自适应.(一番交涉下来,最终是如果弹窗里面有table的话,我们给table的高度自适应,普通表单不需要). 确定了需求,准 ...

  9. php textarea 默认值,html中的textarea属性大全(设置默认值 高度自适应 获取内容 限制输入字数 placeholder)...

    1.textarea设置默认值 HTML: 此段代码设置一个textarea文本框 并且设置为隐藏 2.textarea高度自适应 今天需要些一个回复评论的页面,设计师给的初始界面就是一个只有一行的框 ...

最新文章

  1. beautifulsoup里面的find()和findall()小代码测试
  2. linux系统的编译原理,GCC编译原理_Linux编程_Linux公社-Linux系统门户网站
  3. SpringMVC访问静态页面
  4. c语言斐波那契数列_剑指Offer-10-I.斐波那契数列
  5. mysql分析表_MySQL分析表有什么用
  6. SpringCloud面试题及答案
  7. Linux故障之grub
  8. Hadoop伪分布式搭建(本人新手,欢迎大家多多指导和关照)
  9. Flink Weekly | 每周社区动态更新(附5月活跃榜单)
  10. Spring Cloud Zuul 1(API 网关服务)
  11. 发票识别 表格票据识别
  12. English语法_形容词-排序
  13. SQL中数据类型转换
  14. 安卓手机变Linux服务器丨AidLux上手体验
  15. 如何在Mac版达芬奇中安装使用LUT调色预设?达芬奇lut调色预设安装使用教程
  16. Android applink 踩坑指南
  17. es 按距离查询排序
  18. word快键键-提升工作效率的利器
  19. 查询电脑服务器信息的具体方法
  20. 用通俗易懂的方式讲解Transformers

热门文章

  1. Symbian程序安装不成功的解决方法
  2. 使用C/C++制作简单的俄罗斯方块 一
  3. java基于springboot+vue的驾校学车报名预约管理系统 nodejs+element
  4. 计算机网络学网络制图吗,计算机网络论文发表简述计算机设计制图教学改革
  5. php本地安装mysql报错443_Mysql性能剖析工具--Anemometer部署
  6. html5什么网站知乎,老司机秒懂的5个资源网站,知乎超过10万人推荐,竟被我挖掘到了...
  7. 算法题 硬币组合问题
  8. sqlite的count
  9. 数据处理时如何解决噪声数据?
  10. js通过IP地址获取所在城市