mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* perf: change to import-x * feat: add rules * chore: fix rule * chore: fix * chore: fix * chore: fix * style: `pnpm lint:fix` * Revert "style: `pnpm lint:fix`" This reverts commitdb0116a288. * Revert "chore: fix" This reverts commit69c82a90c0. * chore: fix * style: `pnpm lint:fix` * fix: lint * chore: `pnpm format`
78 lines
1.7 KiB
Vue
78 lines
1.7 KiB
Vue
<template>
|
|
<el-form
|
|
ref="ruleFormRef"
|
|
style="max-width: 600px"
|
|
:model="ruleForm"
|
|
:rules="rules"
|
|
>
|
|
<el-form-item label="name" prop="name">
|
|
<el-mention v-model="ruleForm.name" :options="options" />
|
|
</el-form-item>
|
|
<el-form-item label="desc" prop="desc">
|
|
<el-mention v-model="ruleForm.desc" type="textarea" :options="options" />
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="submitForm(ruleFormRef)">
|
|
Submit
|
|
</el-button>
|
|
<el-button @click="resetForm(ruleFormRef)">Reset</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { reactive, ref } from 'vue'
|
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
|
interface RuleForm {
|
|
name: string
|
|
desc: string
|
|
}
|
|
const ruleFormRef = ref<FormInstance>()
|
|
const ruleForm = reactive<RuleForm>({
|
|
name: '',
|
|
desc: '',
|
|
})
|
|
|
|
const options = ref([
|
|
{
|
|
label: 'Fuphoenixes',
|
|
value: 'Fuphoenixes',
|
|
},
|
|
{
|
|
label: 'kooriookami',
|
|
value: 'kooriookami',
|
|
},
|
|
{
|
|
label: 'Jeremy',
|
|
value: 'Jeremy',
|
|
},
|
|
{
|
|
label: 'btea',
|
|
value: 'btea',
|
|
},
|
|
])
|
|
|
|
const rules = reactive<FormRules<RuleForm>>({
|
|
name: [{ required: true, message: 'Please input name', trigger: 'blur' }],
|
|
desc: [{ required: true, message: 'Please input desc', trigger: 'blur' }],
|
|
})
|
|
|
|
const submitForm = async (formEl: FormInstance | undefined) => {
|
|
if (!formEl) return
|
|
await formEl.validate((valid, fields) => {
|
|
if (valid) {
|
|
console.log('submit!')
|
|
} else {
|
|
console.log('error submit!', fields)
|
|
}
|
|
})
|
|
}
|
|
|
|
const resetForm = (formEl: FormInstance | undefined) => {
|
|
if (!formEl) return
|
|
formEl.resetFields()
|
|
}
|
|
</script>
|