javascript - How to use loading in vue action
世界只因有你
世界只因有你 2017-05-19 10:20:47
0
1
539

This is how the loading state is generally used in Vue

getData(){
    this.loading = true;
    get(api).then(res => {
        this.data = res;
        this.loading = false;
    })
}

But how to use it in the vuex action? The following example uses a public loading and found that it does not work. The loading state should be local. So how to control the loading state in vuex?

  const actions = {
  getProductInfo({commit}){
    commit(types.LOADING, true)
    api.xxx()
      .then(res => {
        commit(types.PRODUCTINFO, res.data)
        commit(types.LOADING, false)
      })
  },
世界只因有你
世界只因有你

reply all(1)
phpcn_u1582

Following your second example,
put the loading flag in the state, and the component gets whether it is loading through the state

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!