element ui 返回上一页后并刷新
要实现返回上一页并刷新的功能,可以使用以下步骤:
-
在后退按钮的点击事件中,调用 window.location.reload() 方法刷新页面。
-
在前一页的页面中,使用 session storage 存储需要刷新的数据,例如表单中的数据。
-
在前一页的页面中,使用 created 钩子函数检查 session storage 中是否存储了需要刷新的数据,并将数据回填到表单中。
示例代码如下:
// 后退按钮的点击事件 goBack() { // 刷新页面 window.location.reload(); }
// 前一页的页面 export default { data() { return { formData: { // 表单数据 } } }, created() { // 检查 session storage 是否存储了需要刷新的数据 const data = sessionStorage.getItem('formData'); if (data) { // 将数据回填到表单中 this.formData = JSON.parse(data); // 清空 session storage sessionStorage.removeItem('formData'); } }, methods: { // 提交表单 onSubmit() { // 存储需要刷新的数据到 session storage sessionStorage.setItem('formData', JSON.stringify(this.formData)); // 跳转到下一页 this.$router.push('/next-page'); } }
原文地址: https://www.cveoy.top/t/topic/cv0l 著作权归作者所有。请勿转载和采集!