Skip to content

Commit 435b2ff

Browse files
committed
chore: optimize the code of caching tabs;
1 parent bad4456 commit 435b2ff

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/layouts/tabs/TabsView.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,17 @@ export default {
228228
* 加载缓存的 tabs
229229
*/
230230
loadCachedTabs() {
231-
const cachedTabs = sessionStorage.getItem(process.env.VUE_APP_TBAS_KEY)
232-
if (cachedTabs) {
231+
const cachedTabsStr = sessionStorage.getItem(process.env.VUE_APP_TBAS_KEY)
232+
if (cachedTabsStr) {
233233
try {
234-
const tabs = JSON.parse(cachedTabs)
235-
if (tabs.length > 0) {
236-
this.pageList = tabs
234+
const cachedTabs = JSON.parse(cachedTabsStr)
235+
if (cachedTabs.length > 0) {
236+
this.pageList = cachedTabs
237237
}
238-
sessionStorage.removeItem(process.env.VUE_APP_TBAS_KEY)
239238
} catch (e) {
240239
console.warn('failed to load cached tabs, got exception:', e)
240+
} finally {
241+
sessionStorage.removeItem(process.env.VUE_APP_TBAS_KEY)
241242
}
242243
}
243244
},

0 commit comments

Comments
 (0)