Refactor #4821
parent
9ae8d5b413
commit
d5742af12c
|
@ -11,19 +11,41 @@ import DockSub from './DockSub.vue';
|
||||||
export default {
|
export default {
|
||||||
name: 'Dock',
|
name: 'Dock',
|
||||||
extends: BaseDock,
|
extends: BaseDock,
|
||||||
|
matchMediaListener: null,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
query: null,
|
||||||
queryMatches: false
|
queryMatches: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const query = matchMedia(`(max-width: ${this.breakpoint})`);
|
this.bindMatchMediaListener();
|
||||||
|
},
|
||||||
|
beforeUnmount() {
|
||||||
|
this.unbindMatchMediaListener();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
bindMatchMediaListener() {
|
||||||
|
if (!this.matchMediaListener) {
|
||||||
|
const query = matchMedia(`(max-width: ${this.breakpoint})`);
|
||||||
|
|
||||||
this.queryMatches = query.matches;
|
this.query = query;
|
||||||
|
this.queryMatches = query.matches;
|
||||||
|
|
||||||
query.addEventListener('change', () => {
|
this.matchMediaListener = () => {
|
||||||
this.queryMatches = query.matches;
|
this.queryMatches = query.matches;
|
||||||
});
|
this.mobileActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.query.addEventListener('change', this.matchMediaListener);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unbindMatchMediaListener() {
|
||||||
|
if (this.matchMediaListener) {
|
||||||
|
this.query.removeEventListener('change', this.matchMediaListener);
|
||||||
|
this.matchMediaListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
containerClass() {
|
containerClass() {
|
||||||
|
|
Loading…
Reference in New Issue