Skip to content

Commit 9c3fa2a

Browse files
committed
refactor: App deviceEnquire
1 parent 9140840 commit 9c3fa2a

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/App.vue

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,17 @@
88

99
<script>
1010
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
11-
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device'
11+
import { AppDeviceEnquire } from '@/utils/mixin'
1212
1313
export default {
14+
mixins: [AppDeviceEnquire],
1415
data () {
1516
return {
1617
locale: zhCN
1718
}
1819
},
1920
mounted () {
20-
const { $store } = this
21-
deviceEnquire(deviceType => {
22-
switch (deviceType) {
23-
case DEVICE_TYPE.DESKTOP:
24-
$store.commit('TOGGLE_DEVICE', 'desktop')
25-
$store.dispatch('setSidebar', true)
26-
break
27-
case DEVICE_TYPE.TABLET:
28-
$store.commit('TOGGLE_DEVICE', 'tablet')
29-
$store.dispatch('setSidebar', false)
30-
break
31-
case DEVICE_TYPE.MOBILE:
32-
default:
33-
$store.commit('TOGGLE_DEVICE', 'mobile')
34-
$store.dispatch('setSidebar', true)
35-
break
36-
}
37-
})
21+
3822
}
3923
}
4024
</script>

src/utils/mixin.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import Vue from 'vue'
2-
import { DEVICE_TYPE } from '@/utils/device'
2+
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device'
33
import { mapState } from 'vuex'
44

55
// const mixinsComputed = Vue.config.optionMergeStrategies.computed
@@ -50,4 +50,24 @@ const mixinDevice = {
5050
}
5151
}
5252

53-
export { mixin, mixinDevice }
53+
const AppDeviceEnquire = {
54+
mounted () {
55+
const { $store } = this
56+
deviceEnquire(deviceType => {
57+
switch (deviceType) {
58+
case DEVICE_TYPE.DESKTOP:
59+
$store.commit('TOGGLE_DEVICE', 'desktop')
60+
break
61+
case DEVICE_TYPE.TABLET:
62+
$store.commit('TOGGLE_DEVICE', 'tablet')
63+
break
64+
case DEVICE_TYPE.MOBILE:
65+
default:
66+
$store.commit('TOGGLE_DEVICE', 'mobile')
67+
break
68+
}
69+
})
70+
}
71+
}
72+
73+
export { mixin, AppDeviceEnquire, mixinDevice }

0 commit comments

Comments
 (0)