Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue] 切换路由时,需要保存草稿的功能,怎么实现呢? #417

Open
haizhilin2013 opened this issue Jun 22, 2019 · 7 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 切换路由时,需要保存草稿的功能,怎么实现呢?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@wenyejie
Copy link

在beforeDestroy中加入check功能,
当检测到有草稿时, 自动保存到vuex或者storage中或者window中等等

但是我要说的是, 这种方法是不靠谱的, 如果我是刷新页面呢!
建议采用, 实施保存操作, 保存在storage中较为靠谱, 当然这种操作牺牲是比较多的

具体看业务场景

@yalishizhude
Copy link

在beforeDestroy中加入check功能,
当检测到有草稿时, 自动保存到vuex或者storage中或者window中等等

但是我要说的是, 这种方法是不靠谱的, 如果我是刷新页面呢!
建议采用, 实施保存操作, 保存在storage中较为靠谱, 当然这种操作牺牲是比较多的

具体看业务场景

可以用beforeDestroy结合window.onbeforeunload解决性能问题

@XSJXSJ111
Copy link

用keep-alive缓存那个路由

@wzzz90
Copy link

wzzz90 commented Aug 9, 2019

beforeRouteLeave

@lostimever
Copy link

你这题目想说明的是,切换路由时自动或提示保存草稿功能吗?
如果是这样

beforeRouteLeave (to, from, next) {
  if(用户已经输入信息){
    //出现弹窗提醒保存草稿,或者自动后台为其保存
    
  }else{
    next(true);//用户离开
  }

}

@famingyuan
Copy link

面试如果要问这种问题,等于得背API

@Drikold
Copy link

Drikold commented Jul 26, 2021

https://blog.csdn.net/loyd3/article/details/118188179

这个离开守卫通常用来禁止用户在还未保存修改前突然离开。该导航可以通过 next(false) 来取消。

beforeRouteLeave (to, from, next) {
  const answer = window.confirm('Do you really want to leave? you have unsaved changes!')
  if (answer) {
    next()
  } else {
    next(false)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

8 participants