mpvue
mpvue copied to clipboard
IOS端 textarea 无发获取value值
代码实践:
同问,出在苹果6s手机上,调试的时候发现v-model没有用,@input事件也没有被触发,求解答一下
可以试试用自定组件裹一层,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 ,好像不行,我用了直接报错了。。。
报什么错?引用的时候还需要使用 usingComponents 在 json 里面定义,对应的自定义组件也要输出到 dist 目录下。这个方案我们以及用在线上了。
@elcarim5efil 这里是不是不能发图片,我Email给你了
<textarea
placeholder="说点什么吧..."
v-bind:maxlength="300"
v-model="desc"
/>
在textarea外套一层div 加一个v-if="isShowTextarea" isShowTextarea 在data中设置为true即可,亲测可用
<textarea placeholder="说点什么吧..." v-bind:maxlength="300" v-model="desc" />
在textarea外套一层div 加一个v-if="isShowTextarea" isShowTextarea 在data中设置为true即可,亲测可用
感谢,you save my life.