fix: [el-form] button type is reset and reset form (#3445)

* fix: [el-form] button type is reset and reset form

* fix: [el-form] button type is reset and reset form

* fix: [el-form] button type is reset and reset form
This commit is contained in:
啝裳 2021-09-17 11:15:49 +08:00 committed by GitHub
parent 9a160450ea
commit f66b046872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,25 +24,32 @@
</template>
<script lang="ts">
import isEmpty from 'lodash/isEmpty'
import { computed, inject, defineComponent } from 'vue'
import { useFormItem } from '@element-plus/hooks'
import { elButtonGroupKey } from '@element-plus/tokens'
import { elButtonGroupKey, elFormKey } from '@element-plus/tokens'
import { buttonEmits, buttonProps } from './button'
export default defineComponent({
name: 'ElButton',
props: buttonProps,
emits: buttonEmits,
setup(_, { emit }) {
setup(props, { emit }) {
const elBtnGroup = inject(elButtonGroupKey, undefined)
const { size: buttonSize, disabled: buttonDisabled } = useFormItem({
size: computed(() => elBtnGroup?.size),
})
const handleClick = (evt: MouseEvent) => emit('click', evt)
const elForm = inject(elFormKey, undefined)
const handleClick = (evt: MouseEvent) => {
if (props.nativeType === 'reset' && !isEmpty(elForm)) {
elForm?.resetFields()
}
emit('click', evt)
}
return {
buttonSize,