2016-11-04 12 views
0

* .vueでデータを初期化したいが、 'created'のメソッドは一度しか実行されないので、いつでもメソッドが実行されるangulajsの指令「ng-init」とまったく同じですか?どうもありがとう!anglejsのng-initのようにvue.jsに関数またはメソッドがありますか?

+0

あなたは 'created'がないこと、正確' NG-init'が何をするのか説明してもらえますか? – nils

+0

@nils 'ng-init'は、ページを入力するたびに関数を呼び出すが、ライフサイクルで一度呼び出すだけで '作成'されます。 – AZmake

+0

ルータでナビゲートする場合(例: 'vue-router')のようにページを入力しますか? – nils

答えて

1

vue 1のvue-routerには、これまでにactivateフックがありました。

私が見る限り、2行目では少し複雑です。状態を初期化する方法がinitあるとします。

The $route object changes when you navigate, so you can watch it and reinitialize your data, every time the component exists.

created() { 
    // fetch the data when the view is created and the data is 
    // already being observed 
    this.init() 
    }, 
    watch: { 
    // call again the method if the route changes 
    '$route': 'init' 
    }, 
関連する問題