Answer the question
In order to leave comments, you need to log in
How to return an object to its initial state?
Regular object in data in Vue.js
data() {
return {
info : {
state1:10,
state2:20,
state3:30,
}
}
}
Answer the question
In order to leave comments, you need to log in
function initialData () {
return {
info: {
state1: 10,
state2: 20,
state3: 30
}
}
}
export default {
data () {
return initialData()
},
methods: {
flush () {
const data = initialData()
Object.keys(data).forEach(key => {
this[key] = initialData[key]
})
}
}
}
initialState () {
this.info: {
state1: null,
state2: null,
state3: null
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question