今天在写项目的时候遇到一个问题:!!无论怎么按键盘都无法输入,也无法修改已经在数据,反正就是天打不动的呐。
小编这里呢是想在弹出的模态框里,进行“回复”,如果选中的问题已经有所回复,那么就可以修改,如下图中所示:
下面是这个模态框的代码
<!-- 点击回复弹出的模态框 -->
<el-dialog title="回复提问" :visible.sync="dialogVisible" width="45%">
<el-form :model="replyForm" label-width="80px" size="small" ref="docForm">
<el-form-item label="提问内容" prop="name">
<template>
<span>{{this.comment}}</span>
</template>
</el-form-item>
<el-form-item label="提问时间" prop="name">
<template>
<span>{{this.commentTime | dateParse}}</span>
</template>
</el-form-item>
<el-form-item
label="回复"
prop="reply"
:rules="[{ required: true, message: '请输入回复内容', trigger: 'blur' }]"
>
<el-input type="textarea" :rows="2" v-model="replyForm.reply"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button class="el-button-type" size="small" @click="dialogVisible = false">取 消</el-button>
<el-button class="el-button–primary" size="small" type="primary" @click="saveHandler">确 定</el-button>
</span>
</el-dialog>
对这个模态框中数据和input的处理,代码如下:
// 点击回复
replyHandler(row) {
this.dialogVisible = true;
localStorage.setItem('id',row.id)
this.comment = row.comment
this.commentTime = row.commentTime
this.replyForm.reply = row.reply ? row.reply : ""
},
因为“回复”原本是有内容的,所以要将原本的内容赋给模态框中的input,在此基础上进行改变或者新添回复内容,但是问题来了,input里面是怎么也输入不了东西了,也不能删除原有的内容,但是呢,如果将this.replyForm.reply = row.reply ? row.reply : ""
这行代码注释掉,又是可以的,那么可以确定并不是我们模态框或者导入element-ui组件的错误。
那么小编是怎么解决的呢?其实只需要修改一处小小的地方。
小编原先给的返回的数据是这样的===>
data() {
return {
dialogVisible: false,
replyForm: {},
comment:'',
commentTime:''
};
},
这里将上面的replyForm: {}
改成replyForm: { reply:"" }
即可。
总结一下:如果input无法输入,那么就给它单独领出来赋值,给赋值一个空字符串就行,原因小编查了一下,有说是因为嵌套的组件太深了,导致就无法使用;还说另一个方法是使用@input事件,在输入时进行强制刷新,使用$forceUpdate()
,这个方法小编么有使用过,希望能有所帮助。