mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-24 11:05:17 +08:00
refactor(components): [alert] switch to script-setup syntax (#6066)
This commit is contained in:
parent
c2fe2a4f05
commit
56b37b6a34
@ -32,62 +32,49 @@
|
||||
{{ closeText }}
|
||||
</div>
|
||||
<el-icon v-else :class="ns.e('close-btn')" @click="close">
|
||||
<close />
|
||||
<Close />
|
||||
</el-icon>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed, ref } from 'vue'
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, useSlots } from 'vue'
|
||||
import { ElIcon } from '@element-plus/components/icon'
|
||||
import { TypeComponents, TypeComponentsMap } from '@element-plus/utils'
|
||||
import { useNamespace } from '@element-plus/hooks'
|
||||
import { alertProps, alertEmits } from './alert'
|
||||
|
||||
export default defineComponent({
|
||||
const { Close } = TypeComponents
|
||||
|
||||
defineOptions({
|
||||
name: 'ElAlert',
|
||||
|
||||
components: {
|
||||
ElIcon,
|
||||
...TypeComponents,
|
||||
},
|
||||
|
||||
props: alertProps,
|
||||
emits: alertEmits,
|
||||
|
||||
setup(props, { emit, slots }) {
|
||||
const ns = useNamespace('alert')
|
||||
|
||||
// state
|
||||
const visible = ref(true)
|
||||
|
||||
// computed
|
||||
const iconComponent = computed(
|
||||
() => TypeComponentsMap[props.type] || TypeComponentsMap['info']
|
||||
)
|
||||
const isBigIcon = computed(() =>
|
||||
props.description || slots.default ? ns.is('big') : ''
|
||||
)
|
||||
const isBoldTitle = computed(() =>
|
||||
props.description || slots.default ? ns.is('bold') : ''
|
||||
)
|
||||
|
||||
// methods
|
||||
const close = (evt: MouseEvent) => {
|
||||
visible.value = false
|
||||
emit('close', evt)
|
||||
}
|
||||
|
||||
return {
|
||||
ns,
|
||||
visible,
|
||||
iconComponent,
|
||||
isBigIcon,
|
||||
isBoldTitle,
|
||||
close,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const props = defineProps(alertProps)
|
||||
const emit = defineEmits(alertEmits)
|
||||
const slots = useSlots()
|
||||
|
||||
const ns = useNamespace('alert')
|
||||
|
||||
// state
|
||||
const visible = ref(true)
|
||||
|
||||
// computed
|
||||
const iconComponent = computed(
|
||||
() => TypeComponentsMap[props.type] || TypeComponentsMap['info']
|
||||
)
|
||||
const isBigIcon = computed(
|
||||
() => props.description || { [ns.is('big')]: slots.default }
|
||||
)
|
||||
const isBoldTitle = computed(
|
||||
() => props.description || { [ns.is('bold')]: slots.default }
|
||||
)
|
||||
|
||||
// methods
|
||||
const close = (evt: MouseEvent) => {
|
||||
visible.value = false
|
||||
emit('close', evt)
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user