可通过this.$watch()监测input组件的输入值和@change事件,当输入值超过限定字数给出弹窗提示。 <input class="input-text" id="text1" value="{{content}}" style="placeholder-color:#FF0000;" @change="handleInputValueChanged"></input>
test(e) { this.$watch('this.content', 'handleInputValueChanged') }, handleInputValueChanged: function (e) { var that = this; var inputText = e.value; console.log('handleInputValueChanged:' + this.content); if (inputText.length >= 5) { console.log('value length greater than 5'); prompt.showToast({ message: "消息最长为5", gravity: 'center' }) } },
|