mpvue icon indicating copy to clipboard operation
mpvue copied to clipboard

IOS端 textarea 无发获取value值

Open GTRgoSky opened this issue 6 years ago • 7 comments

代码实践:

GTRgoSky avatar Dec 21 '18 01:12 GTRgoSky

同问,出在苹果6s手机上,调试的时候发现v-model没有用,@input事件也没有被触发,求解答一下

leochen-g avatar Dec 27 '18 15:12 leochen-g

可以试试用自定组件裹一层,textarea 应该是用 native 组件实现的,dataset 貌似无法动态绑定数据,用小程序自定义组件包一层再弹出来,就可以了。

index.wxml

<textarea
  placeholder="{{placeholder}}"
  placeholder-style="{{placeholderStyle}}"
  placeholder-class="{{placeholderClass}}"
  disabled="{{disabled}}"
  auto-focus="{{autoFocus}}"
  focus="{{focue}}"
  auto-height="{{autoHeight}}"
  fixed="{{fixed}}"
  cursor-spacing="{{cursorSpacing}}"
  cursor="{{cursor}}"
  show-confirm-bar="{{showConfirmBar}}"
  selection-start="{{selectionStart}}"
  selection-end="{{selectionEnd}}"
  adjust-position="{{adjustPosition}}"
  maxlength="{{maxlength}}"
  value="{{value}}"

  bindinput="proxy"
  bindblur="proxy"
  bindfocus="proxy"
  bindblur="proxy"
  bindlinechange="proxy"
>
</textarea>

index.js

Component({
    properties: {
        placeholder: { type: String, value: '' },
        placeholderStyle: { type: String, value: '' },
        placeholderClass: { type: String, value: '' },
        disabled: { type: Boolean, value: false },
        autoFocus: { type: Boolean, value: false },
        focus: { type: Boolean, value: false },
        autoHeight: { type: Boolean, value: false },
        fixed: { type: Boolean, value: false },
        cursorSpacing: { type: Number | String, value: 0 },
        cursor: { type: Number, value: 0 },
        showConfirmBar: { type: Boolean, value: true },
        selectionStart: { type: Number, value: -1 },
        selectionEnd: { type: Number, value: -1 },
        adjustPosition: { type: Boolean, value: true },
        maxlength: { type: Number, value: 140 },
        value: { type: String, value: '' }
    },
    methods: {
        proxy(e) {
            this.triggerEvent(e.type, e.detail);
        }
    }
});

index.wxss

textarea{
	width:inherit;
	height:inherit;
	display:inherit;
	position:inherit;
}

elcarim5efil avatar Jan 03 '19 13:01 elcarim5efil

@elcarim5efil ,好像不行,我用了直接报错了。。。

nicoleffect avatar Jan 07 '19 15:01 nicoleffect

报什么错?引用的时候还需要使用 usingComponents 在 json 里面定义,对应的自定义组件也要输出到 dist 目录下。这个方案我们以及用在线上了。

elcarim5efil avatar Jan 08 '19 01:01 elcarim5efil

@elcarim5efil 这里是不是不能发图片,我Email给你了

nicoleffect avatar Jan 08 '19 08:01 nicoleffect

    <textarea
      placeholder="说点什么吧..."
      v-bind:maxlength="300"
      v-model="desc"
    />

在textarea外套一层div 加一个v-if="isShowTextarea" isShowTextarea 在data中设置为true即可,亲测可用

AganYa avatar Jun 05 '19 02:06 AganYa

    <textarea
      placeholder="说点什么吧..."
      v-bind:maxlength="300"
      v-model="desc"
    />

在textarea外套一层div 加一个v-if="isShowTextarea" isShowTextarea 在data中设置为true即可,亲测可用

感谢,you save my life.

cat-walk avatar Jan 06 '21 05:01 cat-walk