|
1 | 1 | import classNames from '../_util/classNames';
|
2 | 2 | import type { PropType, ExtractPropTypes, CSSProperties } from 'vue';
|
3 |
| -import { inject, defineComponent, ref, watch, onMounted, onBeforeUnmount, provide } from 'vue'; |
| 3 | +import { |
| 4 | + watchEffect, |
| 5 | + inject, |
| 6 | + defineComponent, |
| 7 | + ref, |
| 8 | + watch, |
| 9 | + onMounted, |
| 10 | + onBeforeUnmount, |
| 11 | + provide, |
| 12 | +} from 'vue'; |
4 | 13 | import PropTypes from '../_util/vue-types';
|
5 | 14 | import { tuple } from '../_util/type';
|
6 | 15 | import initDefaultProps from '../_util/props-util/initDefaultProps';
|
@@ -114,18 +123,25 @@ export default defineComponent({
|
114 | 123 | siderHook && siderHook.addSider(uniqueId);
|
115 | 124 |
|
116 | 125 | onMounted(() => {
|
117 |
| - if (typeof window !== 'undefined') { |
118 |
| - const { matchMedia } = window; |
119 |
| - if (matchMedia! && props.breakpoint && props.breakpoint in dimensionMaxMap) { |
120 |
| - mql = matchMedia(`(max-width: ${dimensionMaxMap[props.breakpoint]})`); |
121 |
| - try { |
122 |
| - mql.addEventListener('change', responsiveHandler); |
123 |
| - } catch (error) { |
124 |
| - mql.addListener(responsiveHandler); |
| 126 | + watchEffect(() => { |
| 127 | + try { |
| 128 | + mql?.removeEventListener('change', responsiveHandler); |
| 129 | + } catch (error) { |
| 130 | + mql?.removeListener(responsiveHandler); |
| 131 | + } |
| 132 | + if (typeof window !== 'undefined') { |
| 133 | + const { matchMedia } = window; |
| 134 | + if (matchMedia! && props.breakpoint && props.breakpoint in dimensionMaxMap) { |
| 135 | + mql = matchMedia(`(max-width: ${dimensionMaxMap[props.breakpoint]})`); |
| 136 | + try { |
| 137 | + mql.addEventListener('change', responsiveHandler); |
| 138 | + } catch (error) { |
| 139 | + mql.addListener(responsiveHandler); |
| 140 | + } |
| 141 | + responsiveHandler(mql); |
125 | 142 | }
|
126 |
| - responsiveHandler(mql); |
127 | 143 | }
|
128 |
| - } |
| 144 | + }); |
129 | 145 | });
|
130 | 146 | onBeforeUnmount(() => {
|
131 | 147 | try {
|
|
0 commit comments