App.vue
<template>
<router-view></router-view>
</template>
<script>
import { mapActions, mapMutations } from 'vuex';
import _ from 'lodash';
export default {
created() {
this.onResize();
this.onResizeListener = _.throttle(this.onResize, 200);
window.addEventListener('resize', this.onResizeListener);
this.initSessionId();
this.initAccount();
},
beforeDestroy() {
window.removeEventListener('resize', this.onResizeListener);
},
methods: {
...mapMutations('app', ['setWidth']),
...mapActions('account', ['initSessionId', 'initAccount']),
onResize() {
this.setWidth(window.innerWidth);
},
},
};
</script>