Vue中的input输入框无法输入

Vue中的input输入框无法输入

Vue中的input输入框无法输入
刚开始以为是键盘的问题,然后发现别的地方都可以输入,唯独这个input无法输入,可能因为我循环嵌套了三次,太深入无法渲染

 <el-input     
  v-model="desc"
     type="textarea"
     @input="change($event)"
  />

change(e) {
   this.$forceUpdate()
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用 Vue 的数据绑定和计算属性来实现这个功能。具体实现步骤如下: 1. 在 Vue 的 data 定义一个变量,用于存储 input 输入框的值。 ``` data() { return { inputValue: '' } } ``` 2. 在 input 输入框绑定这个变量,并添加一个 change 事件。 ``` <input type="text" v-model="inputValue" @change="checkInput"> ``` 3. 在 methods 定义 checkInput 方法,用于检查输入框的值是否为空。如果为空,将提示文字变成红色,并在提示文字显示错误信息。 ``` methods: { checkInput() { if (this.inputValue === '') { this.$refs.errorMsg.style.color = 'red'; this.$refs.errorMsg.innerHTML = '输入框不能为空'; } else { this.$refs.errorMsg.style.color = 'black'; this.$refs.errorMsg.innerHTML = ''; } } } ``` 4. 在模板添加一个 span 元素,用于显示错误信息,并添加一个 ref 属性,用于在 checkInput 方法引用这个元素。 ``` <span ref="errorMsg"></span> ``` 5. 在计算属性定义一个变量,用于控制提示文字的显示和隐藏。 ``` computed: { showErrorMsg() { return this.inputValue === ''; } } ``` 6. 在模板绑定这个变量,并根据其值显示或隐藏提示文字。 ``` <span v-show="showErrorMsg" style="color: red">输入框不能为空</span> ``` 完整的代码如下: ``` <template> <div> <input type="text" v-model="inputValue" @change="checkInput"> <span ref="errorMsg" v-show="showErrorMsg" style="color: red"></span> </div> </template> <script> export default { data() { return { inputValue: '' } }, methods: { checkInput() { if (this.inputValue === '') { this.$refs.errorMsg.style.color = 'red'; this.$refs.errorMsg.innerHTML = '输入框不能为空'; } else { this.$refs.errorMsg.style.color = 'black'; this.$refs.errorMsg.innerHTML = ''; } } }, computed: { showErrorMsg() { return this.inputValue === ''; } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值