Element form method resetfields() error
Codes:
// Form Reset export function resetForm(refName) { // The purpose of adding the if condition is to solve the problem of non-existent objects in the console if (this.$refs[refName] ) { this.$refs[refName].resetFields(); } }
Error Messages:
vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading 'indexOf') at VueComponent.resetField (element-ui.common.js?5c96:23528) at eval (element-ui.common.js?5c96:22945) at Array.forEach (<anonymous>) at VueComponent.resetFields (element-ui.common.js?5c96:22944) at VueComponent.resetForm (ruoyi.js?c38a:51) at VueComponent.reset (index.vue?6ced:2165) at VueComponent.handleCopy (index.vue?6ced:2504) at click (index.vue?e6ab:1003) at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854) at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
Solution:
// Form reset export function resetForm(refName) { // The purpose of adding the if condition is to solve the problem of non-existent objects in the console if (this.$refs[refName] !== undefined) { this.$refs[refName].resetFields(); } }
Another possibility for this type of problem is that the prop is not assigned a value, and a similar problem can occur:
<el-form-item label="Self-pickup offer"> <el-input v-model="form.selfOffer" :clearable="true" :disabled="disabled" placeholder="Please enter a discount price" @input="inputCityFloat" > <template slot="append">Yuan</template> </el-input> </el-form-item>