2016-10-13 4 views
3

ich ein Kind-Komponente haben, die diese Methode hat:Vue.js Zugang Elternkomponente

getSubscriptions() { 
    MessageService.subscriptions() 
      this.$parent.loading = true; 
      .then((data) => { 
       if (data.data.subscriptions == null) { 
        this.noSubscriptions = true; 
       } else { 
        this.subscriptions = data.data.subscriptions; 
       } 

       this.$parent.loading = false; 
      }).bind(this); 
} 

So möchte ich zeigen, einen Lastkreis in meinem Elternkomponente ich auf sie wie folgt aus:

this.$parent.loading 

(Meine Eltern Komponente hat ein Datum Attribut namens loading)

Aber wenn ich versuche, dass mit großem Schluck zu kompilieren^I erhalten:

012.351.
[14:52:56] Starting 'browserify'... 
    46 |        } 
    47 | 
> 48 | t       this.$parent.loading = false; 
    |       ^
    49 |       }).bind(this); 
    50 |    }, 
    51 | 
{ SyntaxError: unknown: Unexpected token (48:28) 
    46 |        } 
    47 | 
> 48 | t       this.$parent.loading = false; 
    |       ^
    49 |       }).bind(this); 
    50 |    }, 

Was könnte hier falsch sein?

(Ich verwende Vue.js 1.0)

Antwort

3

Sie sind in der Mitte eines Versprechens Setup eine neue Anweisung setzen. Sie müssen den Code neu anordnen:

this.$parent.loading = true; 
MessageService.subscriptions() 
     .then((data) => { 

Allerdings würde ich nicht direkt auf den Eltern so zugreifen. Es erzeugt eine enge Kopplung zwischen Eltern und Kind - diese Komponente funktioniert nur, wenn das Elternteil ein loading Flag aussetzt.

Schauen Sie stattdessen in custom events.