Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

vue.js - Can I have two seperate state functions?

For example, I hold my states in

state: initialState()

However, I reset this state with a button after some time. Is it possible to add another state that doesn't reset? I'd like to push the current state before reset to an array. So I could have a list of removed states in the history. How should I approach this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure if that's what you mean. But this might do the the trick:

state: initialState(),
stateHistory:[initialState()]

And then you can do this before resetting

stateHistory.push(JSON.parse(JSON.stringify(state))) // creates a deepy copy of your current state
resetState() // reset the state after storing old state

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...