initial version
This commit is contained in:
32
mixins/mobileMixin.js
Normal file
32
mixins/mobileMixin.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useMainStore } from '~/store/pinia';
|
||||
|
||||
const mobileMixin = {
|
||||
setup() {
|
||||
const store = useMainStore();
|
||||
const isMobile = ref(store.isMobile);
|
||||
|
||||
const updateIsMobile = () => {
|
||||
isMobile.value = window.innerWidth <= 768;
|
||||
store.setIsMobile(isMobile.value);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
if (process.client) {
|
||||
updateIsMobile();
|
||||
window.addEventListener('resize', updateIsMobile);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
isMobile,
|
||||
updateIsMobile
|
||||
};
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (process.client) {
|
||||
window.removeEventListener('resize', this.updateIsMobile);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default mobileMixin
|
||||
Reference in New Issue
Block a user