refactor: OperateDrawer 使用defineModel简化代码
This commit is contained in:
parent
526ffd1f4d
commit
7e48682fbe
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, nextTick, onUnmounted, reactive, ref, watch } from 'vue';
|
import { computed, nextTick, onUnmounted, reactive, ref } from 'vue';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -8,22 +8,20 @@ defineOptions({
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title?: string;
|
title?: string;
|
||||||
modelValue?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'update:modelValue', modelValue: boolean): void;
|
(e: 'update:modelValue', modelValue: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const visible = defineModel<boolean>('visible', {
|
|
||||||
default: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
|
const model = defineModel<boolean>({ default: false });
|
||||||
|
|
||||||
const slots = defineSlots();
|
const slots = defineSlots();
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
|
||||||
const state = reactive({ width: 0 });
|
const state = reactive({ width: 0 });
|
||||||
const isFullscreen = ref(false);
|
const isFullscreen = ref(false);
|
||||||
const drawerWidth = computed(() => {
|
const drawerWidth = computed(() => {
|
||||||
@ -53,21 +51,13 @@ onUnmounted(() => {
|
|||||||
window.removeEventListener('resize', getState);
|
window.removeEventListener('resize', getState);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.modelValue,
|
|
||||||
val => {
|
|
||||||
visible.value = val;
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const onUpdateShow = (value: boolean) => {
|
const onUpdateShow = (value: boolean) => {
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NDrawer v-model:show="visible" display-directive="if" :width="drawerWidth" @update:show="onUpdateShow">
|
<NDrawer v-model:show="model" display-directive="if" :width="drawerWidth" @update:show="onUpdateShow">
|
||||||
<NDrawerContent :title="props.title" :native-scrollbar="false" closable header-class="operate-dawer-header">
|
<NDrawerContent :title="props.title" :native-scrollbar="false" closable header-class="operate-dawer-header">
|
||||||
<template #header>
|
<template #header>
|
||||||
{{ props.title }}
|
{{ props.title }}
|
||||||
|
Loading…
Reference in New Issue
Block a user