2016-10-13 12 views
3

私は、このメソッドを持っている子コンポーネントを持っている:Vue.jsアクセス親コンポーネント

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); 
} 

だから私は、私はこのようにアクセス私の親コンポーネントの負荷円を表示したい:

this.$parent.loading 

(私の親コンポーネントはloadingと呼ばれるデータの属性を持っている)しかし、私は^グッとそれをコンパイルしようとすると、私が受け取る:

[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 |    }, 

ここで何が間違っていますか?

あなたは約束のセットアップの途中で新しいステートメントを入れている

答えて

3

(私はVue.js 1.0を使用しています)。コードを並べ替える必要があります:

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

しかし、私はこのように親に直接アクセスしません。親と子のタイトなカップリングが作成されます。このコンポーネントは、親がloadingフラグを公開している場合にのみ機能します。

代わりにcustom eventsを調べてください。

関連する問題