有時候el-input由於嵌套的層級比較多,數據雙向綁定無效。有兩種解決方案,一是減少層級的嵌套,這對於必須嵌套多層的頁面來說,無法解決。
第二種方法:在嵌套的無法進行動態綁定的頁面的輸入框上添加一個input事件,在input執行的方法中強制刷新數據:
<template>
<el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="必填項" prop="name">
<el-input v-model="ruleForm.name" @input="inputChange"></el-input>
</el-form-item>
</el-form>
</template>
<script>
export default { name: '', data() { return { ruleForm: {}, } }, methods: { inputChange(e) { //強制刷新 this.$forceUpdate() } } } </script> <style> </style>