|
1 | 1 | <template>
|
2 | 2 | <view class="left-window-style">
|
3 | 3 | <view class="second-menu">
|
4 |
| - <component v-bind:is="active"></component> |
| 4 | + <!-- <keep-alive> --> |
| 5 | + <component v-bind:is="active" :hasLeftWin="hasLeftWin" :leftWinActive="leftWinActive"></component> |
| 6 | + <!-- </keep-alive> --> |
5 | 7 | </view>
|
6 | 8 | </view>
|
7 | 9 | </template>
|
|
40 | 42 | computed: {
|
41 | 43 | ...mapState({
|
42 | 44 | active: state => state.active,
|
| 45 | + hasLeftWin: state => !state.noMatchLeftWindow, |
| 46 | + leftWinActive: state => state.leftWinActive.split('/')[3], |
43 | 47 | })
|
44 | 48 | },
|
45 | 49 | watch: {
|
46 | 50 | matchLeftWindow: {
|
47 | 51 | immediate: true,
|
48 |
| - handler(newMatches) { |
| 52 | + handler(newMatches) { |
49 | 53 | this.setMatchLeftWindow(newMatches)
|
50 | 54 | }
|
51 |
| - }, |
| 55 | + }, |
| 56 | + // #ifndef VUE3 |
52 | 57 | $route: {
|
53 | 58 | immediate: true,
|
54 |
| - handler(newRoute) { |
55 |
| - if (this.matchLeftWindow) { |
56 |
| - if (newRoute.path === '/') { |
57 |
| - uni.redirectTo({ |
58 |
| - url: 'pages/component/view/view' |
59 |
| - }) |
60 |
| - } else if (!newRoute.matched.length) { |
61 |
| - uni.redirectTo({ |
62 |
| - url: 'pages/error/404' |
63 |
| - }) |
64 |
| - } else { |
65 |
| - let active = newRoute.path.split('/')[2] |
66 |
| - if (this.nav.includes(active)) { |
67 |
| - if (active === 'component') { |
68 |
| - active = 'componentPage' |
69 |
| - } |
70 |
| - if (active === 'template') { |
71 |
| - active = 'templatePage' |
72 |
| - } |
73 |
| - this.setActive(active) |
74 |
| - } |
75 |
| - } |
76 |
| - } |
| 59 | + handler(newRoute) { |
| 60 | + this.handlerRoute(newRoute) |
77 | 61 | }
|
| 62 | + }, |
| 63 | + // #endif |
| 64 | + // #ifdef VUE3 |
| 65 | + $route(newRoute) { |
| 66 | + this.handlerRoute(newRoute) |
78 | 67 | }
|
| 68 | + // #endif |
79 | 69 | },
|
80 | 70 | methods: {
|
81 |
| - ...mapMutations(['setMatchLeftWindow', 'setActive']), |
| 71 | + ...mapMutations(['setMatchLeftWindow', 'setActive', 'setLeftWinActive']), |
| 72 | +
|
| 73 | + handlerRoute(newRoute) { |
| 74 | + if (this.matchLeftWindow) { |
| 75 | + if (newRoute.path === '/') { |
| 76 | + uni.redirectTo({ |
| 77 | + url: 'pages/component/view/view' |
| 78 | + }) |
| 79 | + } else if (!newRoute.matched.length) { |
| 80 | + uni.redirectTo({ |
| 81 | + url: 'pages/error/404' |
| 82 | + }) |
| 83 | + } else { |
| 84 | + this.setLeftWinActive(newRoute.path) |
| 85 | + let active = newRoute.path.split('/')[2] |
| 86 | + if (this.nav.includes(active)) { |
| 87 | + if (active === 'component') { |
| 88 | + active = 'componentPage' |
| 89 | + } |
| 90 | + if (active === 'template') { |
| 91 | + active = 'templatePage' |
| 92 | + } |
| 93 | + this.setActive(active) |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
82 | 98 | }
|
83 | 99 | }
|
84 | 100 | </script>
|
|
0 commit comments