Code structure:Writing method 1 (recommended): <script setup lang="ts"> import { ref, reactive } from 'vue' import type { ElForm } from 'element-plus' const myform = ref<InstanceType<typeof ElForm>>() const formData = reactive({ name: '', subject: '', grade: '' }) // Find const submitForm = () => { const { name, subject, grade } = formData console.log(name, subject, grade) } // Reset const submitReset = () => { myform.value?.resetFields() } </script> <template> <div class="mysearch"> <el-form :model="formData" label-width="80px" ref="myform"> <el-row :gutter="24"> <el-col :span="8"> <el-form-item label="Name" prop="name"> <el-input v-model="formData.name"></el-input> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="Subject" prop="subject"> <el-input v-model="formData.subject"></el-input> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="Grade" prop="grade"> <el-select v-model="formData.grade" placeholder="Please select"> <el-option label="Grade 1" value="shanghai"></el-option> <el-option label="Grade 2" value="beijing"></el-option> </el-select> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="2" :offset="19"> <el-button type="primary" size="medium" @click="submitForm"> Query</el-button> </el-col> <el-col :span="2" :offset="0"> <el-button type="primary" size="medium" @click="submitReset"> Reset</el-button> </el-col> </el-row> </el-form> </div> </template> <style scoped lang="less"> .mysearch { padding: 20px; } </style> Writing method 2: <template> <div class="mysearch"> <el-form ref="myform" :model="formData" label-width="80px"> <el-row :gutter="24"> <el-col :span="8"> <el-form-item label="Name" prop="name"> <el-input v-model="formData.name"></el-input> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="Subject" prop="subject"> <el-input v-model="formData.subject"></el-input> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="Grade" prop="grade"> <el-select v-model="formData.grade" placeholder="Please select"> <el-option label="Grade 1" value="shanghai"></el-option> <el-option label="Grade 2" value="beijing"></el-option> </el-select> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="2" :offset="19"> <el-button type="primary" size="medium" @click="submitForm" >Query</el-button > </el-col> <el-col :span="2" :offset="0"> <el-button type="primary" size="medium" @click="submitReset" >Reset</el-button > </el-col> </el-row> </el-form> </div> </template> <script lang="ts"> import { defineComponent, reactive, ref } from 'vue' import { ElForm } from 'element-plus' export default defineComponent({ setup() { const formData = reactive({ name: '', subject: '', grade: '' }) const myform = ref<InstanceType<typeof ElForm>>() // Find const submitForm = () => { const { name, subject, grade } = formData console.log(name, subject, grade) } // Reset const submitReset = () => { myform.value?.resetFields() } return { formData, myform, submitForm, submitReset } } }) </script> <style scoped lang="less"> .mysearch { padding: 20px; } </style> the difference:
Key points: 1. There is no <el-form-item label="Activity name"> <el-input v-model="form.name"></el-input> </el-form-item> In order to achieve data responsiveness, you need to bind it yourself when writing import { ElForm } from 'element-plus' const myform = ref<InstanceType<typeof ElForm>>() This is the end of this article about Vue3+Element+Ts to implement basic form search reset and other functions. For more related Element Ts form search reset content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Float and Clear Float in Overview Page
>>: How to disable the automatic password saving prompt function of Chrome browser
In MySQL, you can use the SQL statement rename ta...
Learning objectives: Learn to use Windows system ...
Table of contents Horizontal bar chart Dynamicall...
In the past two days, I have been very troubled t...
Optimizing large amounts of database data is a hu...
Table of contents map filter some every findIndex...
0. Why do we need remote development? When develo...
Table of contents 1. Script vim environment 2. Ho...
01. Command Overview Linux provides a rich help m...
Looking at a website is actually like evaluating a...
ref definition: used to register reference inform...
Table of contents 1: Encapsulation idea 2. Packag...
In the previous blog, Xiao Xiong updated the meth...
Table of contents Preface start A little thought ...
Use vue to simply implement a click flip effect f...