vuejs - 浏览器返回时保留表格数据。

问题描述 投票:0回答:1

我不会说英语,我用的是google翻译。

| {}; if( ! state[this.id]) { state[this.id] = {}; } state[this.id].currentPage = this.currentPage; state[this.id].currentPerPage = this.currentPerPage; state[this.id].collFilter = this.collFilter; window.history.replaceState(state, ""); }, }; const watch = { currentPage(newdata) { this.saveStateToHistory(); }, currentPerPage(newdata) { this.saveStateToHistory(); }, collFilter(newdata) { this.saveStateToHistory(); }, }; function created() { var state = window.history.state 我相信在这种情况下,这个标签不适合我(我测试过,没有用)。

vue.js vuejs2
1个回答
0
投票

HTML5历史API似乎就是为这个而生的。

当formdata被改变时,将其保存在历史中与。

window.history.replaceState(state, "");

当(重新)加载页面时,从历史记录中加载:

window.history.state

或者研究一下 window.addEventListener("popstate", function(){...})

例如,在我的列表视图中,我使用。

const methods = { saveStateToHistory() { var state = window.history.state 
© www.soinside.com 2019 - 2024. All rights reserved.