parent
c80c35d8b3
commit
1643e39770
@ -0,0 +1,34 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
isMobile: false,
|
||||
isPad: false,
|
||||
isPC: true,
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.handleScreenResize()
|
||||
window.addEventListener('resize', this.handleScreenResize)
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('resize', this.handleScreenResize)
|
||||
},
|
||||
methods: {
|
||||
handleScreenResize() {
|
||||
const width = document.body.clientWidth
|
||||
if (width < 768) {
|
||||
this.isMobile = true
|
||||
this.isPad = false
|
||||
this.isPC = false
|
||||
} else if (width < 992) {
|
||||
this.isMobile = false
|
||||
this.isPad = true
|
||||
this.isPC = false
|
||||
} else {
|
||||
this.isMobile = false
|
||||
this.isPad = false
|
||||
this.isPC = true
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
export const device = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
device: {
|
||||
isMobile: false,
|
||||
isPad: false,
|
||||
isPC: true,
|
||||
width: 0,
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
setDevice(state, width) {
|
||||
state.device.width = width
|
||||
if (width < 768) {
|
||||
state.device.isMobile = true
|
||||
state.device.isPad = false
|
||||
state.device.isPC = false
|
||||
} else if (width < 992) {
|
||||
state.device.isMobile = false
|
||||
state.device.isPad = true
|
||||
state.device.isPC = false
|
||||
} else {
|
||||
state.device.isMobile = false
|
||||
state.device.isPad = false
|
||||
state.device.isPC = true
|
||||
}
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async setDeviceWidth({ commit }, width) {
|
||||
commit('setDevice', width)
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
isMobile(state) {
|
||||
return state.device.isMobile || window.innerWidth < 768
|
||||
},
|
||||
isPad(state) {
|
||||
return (
|
||||
state.device.isPad ||
|
||||
(window.innerWidth < 992 && window.innerWidth >= 768)
|
||||
)
|
||||
},
|
||||
isPC(state) {
|
||||
return state.device.isPC || window.innerWidth >= 992
|
||||
},
|
||||
width() {
|
||||
return state.device.width
|
||||
},
|
||||
},
|
||||
}
|
Loading…
Reference in new issue