Make 'isMobile' aka 'showMobileMenu' a mixin

This commit is contained in:
Wolfgang Huß 2023-01-31 13:45:01 +01:00
parent c26a037007
commit 12663cbf09
2 changed files with 28 additions and 22 deletions

View File

@ -1,14 +1,14 @@
<template>
<div class="layout-default">
<div class="main-navigation">
<header-menu :showMobileMenu="showMobileMenu" />
<header-menu :showMobileMenu="isMobile" />
</div>
<ds-container>
<div class="main-container">
<nuxt />
</div>
</ds-container>
<page-footer v-if="!showMobileMenu" />
<page-footer v-if="!isMobile" />
<div id="overlay" />
<client-only>
<modal />
@ -17,8 +17,9 @@
</template>
<script>
import HeaderMenu from '~/components/HeaderMenu/HeaderMenu'
import seo from '~/mixins/seo'
import mobile from '~/mixins/mobile'
import HeaderMenu from '~/components/HeaderMenu/HeaderMenu'
import Modal from '~/components/Modal'
import PageFooter from '~/components/PageFooter/PageFooter'
@ -28,27 +29,10 @@ export default {
Modal,
PageFooter,
},
mixins: [seo],
data() {
return {
windowWidth: null,
maxMobileWidth: 810,
}
},
computed: {
showMobileMenu() {
if (!this.windowWidth) return false
return this.windowWidth <= this.maxMobileWidth
},
},
mounted() {
this.windowWidth = window.innerWidth
window.addEventListener('resize', () => {
this.windowWidth = window.innerWidth
})
},
mixins: [seo, mobile],
}
</script>
<style lang="scss">
.main-navigation {
background-color: $color-header-background;

22
webapp/mixins/mobile.js Normal file
View File

@ -0,0 +1,22 @@
export default (mobileWidth = null) => {
return {
data() {
return {
windowWidth: null,
maxMobileWidth: mobileWidth || 810, // greater counts as desktop
}
},
computed: {
isMobile() {
if (!this.windowWidth) return false
return this.windowWidth <= this.maxMobileWidth
},
},
mounted() {
this.windowWidth = window.innerWidth
window.addEventListener('resize', () => {
this.windowWidth = window.innerWidth
})
},
}
}