UNPKG

@bye_past/vue-keep

Version:

缓存你的页面组件, 使得可以比手机APP更好的体验效果

17 lines (12 loc) 564 B
import { HistoryJumpMethods } from './types'; export let historyRecord = JSON.parse(sessionStorage.getItem('keep_history_record') || '[]'); export function handleHistoryRecord(toLocation, method) { const { keepPosition } = history.state; const path = toLocation.fullPath || toLocation.path; historyRecord[keepPosition] = path; if (method === HistoryJumpMethods.pushState) { historyRecord.push(path); historyRecord = historyRecord.slice(0, keepPosition + 1); } sessionStorage.setItem('keep_history_record', JSON.stringify(historyRecord)); }