How do I make undo / redo using Vuex? I am working on a pretty complex app and Vue dev tools helped me a lot to switch between state, so I want that feature on my app. How can I achieve this?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
See: https://vuex.vuejs.org/en/api.html
You can easely use
subscribe(handler: Function)
to register a function that keeps all the states you want from a given Store in an array.Then you can use any of the saved state in that array by giving them as argument to
replaceState(state: Object)
.I've implemented undo-redo as follows:
1) create a plugin for vuex
2) use that plugin
3) save a history of the states in undoRedoHistory
4) use it
If your state is not huge in size than cloning that states is a good approach.