Browse Source

fix: layout sidebar collapsed, close #5373

pull/5380/head
tangjinzhou 3 years ago
parent
commit
5d9afb7d1c
  1. 51
      components/layout/Sider.tsx

51
components/layout/Sider.tsx

@ -1,15 +1,6 @@
import classNames from '../_util/classNames';
import type { PropType, ExtractPropTypes, CSSProperties } from 'vue';
import {
watchEffect,
inject,
defineComponent,
ref,
watch,
onMounted,
onBeforeUnmount,
provide,
} from 'vue';
import { inject, defineComponent, ref, watch, onMounted, onBeforeUnmount, provide } from 'vue';
import PropTypes from '../_util/vue-types';
import { tuple } from '../_util/type';
import initDefaultProps from '../_util/props-util/initDefaultProps';
@ -123,25 +114,31 @@ export default defineComponent({
siderHook && siderHook.addSider(uniqueId);
onMounted(() => {
watchEffect(() => {
try {
mql?.removeEventListener('change', responsiveHandler);
} catch (error) {
mql?.removeListener(responsiveHandler);
}
if (typeof window !== 'undefined') {
const { matchMedia } = window;
if (matchMedia! && props.breakpoint && props.breakpoint in dimensionMaxMap) {
mql = matchMedia(`(max-width: ${dimensionMaxMap[props.breakpoint]})`);
try {
mql.addEventListener('change', responsiveHandler);
} catch (error) {
mql.addListener(responsiveHandler);
watch(
() => props.breakpoint,
() => {
try {
mql?.removeEventListener('change', responsiveHandler);
} catch (error) {
mql?.removeListener(responsiveHandler);
}
if (typeof window !== 'undefined') {
const { matchMedia } = window;
if (matchMedia! && props.breakpoint && props.breakpoint in dimensionMaxMap) {
mql = matchMedia(`(max-width: ${dimensionMaxMap[props.breakpoint]})`);
try {
mql.addEventListener('change', responsiveHandler);
} catch (error) {
mql.addListener(responsiveHandler);
}
responsiveHandler(mql);
}
responsiveHandler(mql);
}
}
});
},
{
immediate: true,
},
);
});
onBeforeUnmount(() => {
try {

Loading…
Cancel
Save