current position:Home>Data acquisition in vuex is assigned to the local problem, and when is vuex data assigned to the local problem

Data acquisition in vuex is assigned to the local problem, and when is vuex data assigned to the local problem

2022-04-29 07:36:58imkaifan

from vuex Get data from , When to assign data to this component ?

1、 stay created Phase assignment to local data

//data:
userForm:{
    
        Name: '',
        Description: '',
        Street: '',
        City: '',
        House: '',
        Province: '',
        Country: '',
        PostCode: ''
      },
// computed:
...mapState("dealWork", {
    
      CustomerInfo: "CustomerInfo"
    })
// created
Object.assgin(this.userForm, this.CustomerInfo)

2、 Using calculation attribute and listening attribute

//data:
userForm:{
    
        Name: '',
        Description: '',
        Street: '',
        City: '',
        House: '',
        Province: '',
        Country: '',
        PostCode: ''
      },
// computed:
...mapState("dealWork", {
    
      CustomerInfo: "CustomerInfo"
    })
// watch
 watch: {
    
    CustomerInfo: {
    
      handler: function (val) {
    
        this.userForm = val;
      },
      deep: true
    }
  },

3、 In some cases, you need to write both :

from vuex Get the data for the first time, and then assign it to the data of this component , Must use watch,
But multi component switching display ( Only watch) If you find it, switch back , There will be no data . So it needs to be in created Phase will vuex Assign the data in to the local

copyright notice
author[imkaifan],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290528481377.html

Random recommended