Skip to content

Commit 0c35127

Browse files
authored
Revert "fix(tabs): 优化多端缓存逻辑,添加增删操作触发子组件销毁重建逻辑 (#3601)"
This reverts commit 337ac61.
1 parent 532c8a7 commit 0c35127

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

packages/renderless/src/tabs-mf/vue.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export const renderless = (props, hooks, { vm, emit, nextTick }) => {
4545
swipeable: computed(() => api.computedSwipeable()),
4646
maxTabSwipeHeight: 0,
4747
itemOrderKey: '',
48-
tabsId: ++uniqueId,
49-
tabPanelCache: {},
50-
includeNames: computed(() => state.items.map((item) => item.name))
48+
tabsId: ++uniqueId
5149
})
5250

5351
const api = {}

packages/vue/src/tabs/src/mobile-first.vue

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="tsx">
22
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'
44
import Carousel from '@opentiny/vue-carousel'
55
import TabBar from './mobile-first/tab-bar.vue'
66
import TabPanel from './mobile-first/tab-panel.vue'
@@ -40,41 +40,31 @@ export default defineComponent({
4040
let tabWrapper
4141
4242
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
4547
}
46-
const panelCache = state.tabPanelCache
47-
const currentName = state.currentItem?.name
4848
49-
const includeNames = state.includeNames
50-
Object.keys(panelCache).forEach((name) => {
51-
if (!includeNames.includes(name)) {
52-
delete panelCache[name]
53-
}
54-
})
49+
vnodes = []
5550
5651
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
7454
}
7555
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+
)
7765
})
66+
67+
tabPanel.push(isVue2 ? <KeepAlive>{vnodes}</KeepAlive> : h(KeepAlive, {}, () => vnodes))
7868
} else {
7969
state.items.forEach((item, i) => {
8070
if (item.lazy && item !== state.currentItem && !item.rendered) {

0 commit comments

Comments
 (0)