|
1 | 1 | <script lang="tsx">
|
2 | 2 | import { renderless, api } from '@opentiny/vue-renderless/tabs-mf/vue'
|
3 |
| -import { props, setup, defineComponent, h, isVue2 } from '@opentiny/vue-common' |
| 3 | +import { props, setup, defineComponent, h, isVue2, KeepAlive } from '@opentiny/vue-common' |
4 | 4 | import Carousel from '@opentiny/vue-carousel'
|
5 | 5 | import TabBar from './mobile-first/tab-bar.vue'
|
6 | 6 | import TabPanel from './mobile-first/tab-panel.vue'
|
@@ -40,41 +40,31 @@ export default defineComponent({
|
40 | 40 | let tabWrapper
|
41 | 41 |
|
42 | 42 | if (optimized) {
|
43 |
| - if (!state.tabPanelCache) { |
44 |
| - state.tabPanelCache = {} |
| 43 | + let defaultSlot, vnodes |
| 44 | +
|
| 45 | + if (state.currentItem) { |
| 46 | + defaultSlot = isVue2 ? state.currentItem.vm.$scopedSlots.default : state.currentItem.slotDefault |
45 | 47 | }
|
46 |
| - const panelCache = state.tabPanelCache |
47 |
| - const currentName = state.currentItem?.name |
48 | 48 |
|
49 |
| - const includeNames = state.includeNames |
50 |
| - Object.keys(panelCache).forEach((name) => { |
51 |
| - if (!includeNames.includes(name)) { |
52 |
| - delete panelCache[name] |
53 |
| - } |
54 |
| - }) |
| 49 | + vnodes = [] |
55 | 50 |
|
56 | 51 | state.items.forEach((item) => {
|
57 |
| - const cacheKey = item.name |
58 |
| - const itemDefSlot = isVue2 ? item.vm.$scopedSlots.default : item.slotDefault |
59 |
| - const props = { |
60 |
| - attrs: { 'data-tag': 'tiny-tab-panel' }, |
61 |
| - class: 'w-full', |
62 |
| - props: { item }, |
63 |
| - key: item.name |
64 |
| - } |
65 |
| -
|
66 |
| - if (!panelCache[cacheKey] && item === state.currentItem) { |
67 |
| - panelCache[cacheKey] = isVue2 |
68 |
| - ? h(TabPanel, { scopedSlots: { default: () => runFnuc(itemDefSlot) }, ...props }) |
69 |
| - : h(TabPanel, props, () => runFnuc(itemDefSlot)) |
70 |
| - } else if (panelCache[cacheKey]) { |
71 |
| - if (panelCache[cacheKey].elm) { |
72 |
| - panelCache[cacheKey].elm.style.display = item.name === currentName ? 'block' : 'none' |
73 |
| - } |
| 52 | + if (item !== state.currentItem) { |
| 53 | + return |
74 | 54 | }
|
75 | 55 |
|
76 |
| - tabPanel.push(panelCache[cacheKey]) |
| 56 | + vnodes.push( |
| 57 | + isVue2 |
| 58 | + ? h(TabPanel, { |
| 59 | + props: { item }, |
| 60 | + key: state.currentItem.name, |
| 61 | + scopedSlots: { default: () => runFnuc(defaultSlot) } |
| 62 | + }) |
| 63 | + : h(TabPanel, { props: { item }, key: state.currentItem.name }, () => runFnuc(defaultSlot)) |
| 64 | + ) |
77 | 65 | })
|
| 66 | +
|
| 67 | + tabPanel.push(isVue2 ? <KeepAlive>{vnodes}</KeepAlive> : h(KeepAlive, {}, () => vnodes)) |
78 | 68 | } else {
|
79 | 69 | state.items.forEach((item, i) => {
|
80 | 70 | if (item.lazy && item !== state.currentItem && !item.rendered) {
|
|
0 commit comments