取消链接状态表单存储

时间:2020-09-07 16:45:57

标签: vue.js vuex

我遇到了问题

  data() {
    return {
      list: [],
      initState: { id: null, data: null }
    }
  },
  computed: {    
     ...mapState({
        contacts: (state) => state.ContactBook.Contacts
      })
     },},
      methods: {
        setinitState(payload) {
          this.initState.data = contacts[this.contactID]
        },

如何使 this.initState 静态?我需要联系人[this.contactID] 更改时没有更改 this.initState ...

2 个答案:

答案 0 :(得分:1)

您可以像这样使用散布运算符,

this.initState.data = {...contacts[this.contanctID]}

Spread Operator MDN

答案 1 :(得分:0)

state.snapshot = JSON.parse(JSON.stringify(state.Contacts [payload]))