|
5 | 5 | </div> |
6 | 6 | </a-locale-provider> |
7 | 7 | </template> |
| 8 | + |
8 | 9 | <script> |
9 | 10 | import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN' |
10 | | - import enquireScreen from '@/utils/device' |
| 11 | + import { deviceEnquire, DEVICE_TYPE } from '@/utils/device' |
11 | 12 | import { version } from 'ant-design-vue' |
12 | 13 |
|
13 | 14 | export default { |
|
17 | 18 | version |
18 | 19 | } |
19 | 20 | }, |
20 | | - created () { |
21 | | - const that = this |
| 21 | + mounted () { |
| 22 | + const { $store } = this |
22 | 23 | console.log('use Ant-Design Of Vue:', version) |
23 | | - enquireScreen(deviceType => { |
24 | | - // tablet |
25 | | - if (deviceType === 0) { |
26 | | - that.$store.commit('TOGGLE_DEVICE', 'mobile') |
27 | | - that.$store.dispatch('setSidebar', false) |
28 | | - } |
29 | | - // mobile |
30 | | - else if (deviceType === 1) { |
31 | | - that.$store.commit('TOGGLE_DEVICE', 'mobile') |
32 | | - that.$store.dispatch('setSidebar', false) |
33 | | - } |
34 | | - else { |
35 | | - that.$store.commit('TOGGLE_DEVICE', 'desktop') |
36 | | - that.$store.dispatch('setSidebar', true) |
37 | | - } |
| 24 | + deviceEnquire(deviceType => { |
38 | 25 |
|
| 26 | + switch (deviceType) { |
| 27 | + case DEVICE_TYPE.DESKTOP: |
| 28 | + $store.commit('TOGGLE_DEVICE', 'desktop') |
| 29 | + $store.dispatch('setSidebar', true) |
| 30 | + break |
| 31 | + case DEVICE_TYPE.TABLET: |
| 32 | + console.log('tablet') |
| 33 | + $store.dispatch('ToggleDevice', 'tablet') |
| 34 | + $store.dispatch('setSidebar', false) |
| 35 | + break |
| 36 | + case DEVICE_TYPE.MOBILE: |
| 37 | + default: |
| 38 | + $store.commit('TOGGLE_DEVICE', 'mobile') |
| 39 | + $store.dispatch('setSidebar', false) |
| 40 | + break |
| 41 | + } |
| 42 | + console.log('deviceType', deviceType) |
39 | 43 | }) |
40 | 44 | } |
41 | 45 | } |
|
0 commit comments