Heim  >  Fragen und Antworten  >  Hauptteil

javascript – So verwenden Sie das Laden in Vue-Aktionen

So wird der Ladezustand im Allgemeinen in Vue verwendet

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

Aber wie verwendet man es in der Aktion von vuex? Das folgende Beispiel verwendet ein öffentliches Laden und stellt fest, dass es nicht funktioniert. Der Ladezustand sollte also lokal sein.

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

Antworte allen(1)Ich werde antworten

  • phpcn_u1582

    phpcn_u15822017-05-19 10:22:47

    承接你的第二个例子,
    把loading的flag放在state中,组件通过state获取是否loading

    Antwort
    0
  • StornierenAntwort