refactor(components): [result] switch to script-setup syntax (#7891)

This commit is contained in:
류한경 2022-05-26 08:54:38 +09:00 committed by GitHub
parent 1069e9ff34
commit ce54397999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 24 deletions

View File

@ -35,7 +35,8 @@ export const resultProps = buildProps({
default: '',
},
icon: {
values: ['success', 'warning', 'info', 'error'],
type: String,
values: ['success', 'warning', 'info', 'error'] as const,
default: 'info',
},
} as const)

View File

@ -24,33 +24,28 @@
</div>
</div>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue'
<script lang="ts" setup>
import { computed } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { IconComponentMap, IconMap, resultProps } from './result'
const COMPONENT_NAME = 'ElResult'
export default defineComponent({
name: COMPONENT_NAME,
props: resultProps,
setup(props) {
const ns = useNamespace('result')
const resultIcon = computed(() => {
const icon = props.icon
const iconClass = icon && IconMap[icon] ? IconMap[icon] : 'icon-info'
const iconComponent =
IconComponentMap[iconClass] || IconComponentMap['icon-info']
defineOptions({
name: 'ElResult',
})
return {
class: iconClass,
component: iconComponent,
}
})
const props = defineProps(resultProps)
return {
ns,
resultIcon,
}
},
const ns = useNamespace('result')
const resultIcon = computed(() => {
const icon = props.icon
const iconClass = icon && IconMap[icon] ? IconMap[icon] : 'icon-info'
const iconComponent =
IconComponentMap[iconClass] || IconComponentMap['icon-info']
return {
class: iconClass,
component: iconComponent,
}
})
</script>