Textarea

多行输入框。扫码体验:

img.jpg

属性名类型默认值描述最低版本
nameString组件名字,用于表单提交获取数据
valueString初始内容
placeholderString占位符
placeholder-styleString指定 placeholder 的样式1.6.0
placeholder-classString指定 placeholder 的样式类1.6.0
disabledBooleanfalse是否禁用
maxlengthNumber140最大长度,当设置为-1时不限制最大长度
focusBooleanfalse获取焦点
auto-heightBooleanfalse是否自动增高
show-countBooleantrue是否渲染字数统计功能1.8.0
controlledBooleanfalse是否为受控组件。为true时,value内容会完全受setData控制1.8.0
onInputEventHandle键盘输入时触发,event.detail = {value: value},可以直接 return 一个字符串以替换输入框的内容
onFocusEventHandle输入框聚焦时触发 event.detail = {value: value}
onBlurEventHandle输入框失去焦点时触发,event.detail = {value: value}
onConfirmEventHandle点击完成时触发,event.detail = {value: value}

Screenshot

image

示例代码

  1. <view class="section">
  2. <textarea onBlur="bindTextAreaBlur" auto-height placeholder="自动变高" />
  3. </view>
  4. <view class="section">
  5. <textarea placeholder="这个只有在按钮点击的时候才聚焦" focus="{{focus}}" />
  6. <view class="btn-area">
  7. <button onTap="bindButtonTap">使得输入框获取焦点</button>
  8. </view>
  9. </view>
  10. <view class="section">
  11. <form onSubmit="bindFormSubmit">
  12. <textarea placeholder="form 中的 textarea" name="textarea"/>
  13. <button form-type="submit"> 提交 </button>
  14. </form>
  15. </view>
  1. Page({
  2. data: {
  3. focus: false,
  4. inputValue: ''
  5. },
  6. bindButtonTap() {
  7. this.setData({
  8. focus: true
  9. })
  10. },
  11. bindTextAreaBlur: function(e) {
  12. console.log(e.detail.value)
  13. },
  14. bindFormSubmit: function(e) {
  15. console.log(e.detail.value.textarea)
  16. }
  17. })

原文: https://docs.alipay.com/mini/component/textarea