表單需加上ref屬性
欄位需加上prop屬性
##
<template> <div class="main"> <el-form ref="resetFormData" :model="formInline"> <el-form-item label="姓名" prop="customerName"> <el-input v-model="formInline.customerName" placeholder="请输入姓名" ></el-input> </el-form-item> <el-button type="warning" @click="resetForm">重置</el-button> </el-form> </div> </template>
<script> import { defineComponent, reactive, ref } from "vue"; export default defineComponent({ setup() { const resetFormData = ref(null); const formInline = reactive({}); const resetForm = () => { resetFormData.value.resetFields(); }; return { resetForm, resetFormData, formInline, }; }, }); </script>
// Vue2.0 Vue.prototype.resetForm = resetForm; //Vue3.0 let app = createApp(App); //... app.config.globalProperties.resetForm = resetForm;
以上是vue3與elementPlus reset重置表單問題怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!