2017-02-17 11 views
0

に私は私の列で作成された取得したい私はlaravelを使用していますし、これは瞬間JS fromnow機能VUEのjs laravel

Vue.http.headers.common['X-CSRF-TOKEN'] = $("#token").attr("value"); 
     new Vue({ 
      el: '#notificationMenu', 
      data: { 
      patients: [] 
      }, 
      created: function(){ 
       this.getPatients(); 
       this.addUsers(); 
      }, 
      methods: { 
       getPatients: function(){ 
         $.getJSON("{{route('api_patients')}}", function(patients){ 
         this.patients = patients; 
        }.bind(this)); 
        setTimeout(this.getPatients, 1000); 
       }, 
       addUsers: function(){ 
       // var newItem = {'name':'asdfasdf','email':'sdfsdf','password':'sdfsdf'} 
       // var input = this.newItem; 
        this.$http.get('/govaccine/addUsers', '').then((response) => { 
        }, (response) => { 
        this.formErrors = response.data; 
        }); 

       } 
      } 

     }); 

私VUEであり、ここで私の見解は

<li class=" notif unread" v-for="patient in patients"> 
         <a href="#"> 
         <div class="messageblock"> 
          <div class="message"><strong>@{{ patient.patient_lname}} @{{ patient.patient_fname}}'s</strong> next vaccination is due on 2017-03-23 for @{{patient.vaccine_name}} 
          </div> 
          <div class="messageinfo"> 
          <i class="icon-trophy"></i>2 hours ago 
          </div> 
      </div> 
     </a> 
    </li> 

ですmoment.jsのfromnow機能を表示して使用します。私は解決策を探すことを試みましたが、私のためには機能しません。

私はrequired('moment')を使用しましたが、これはnpm install -g browserifyでインストールされたbrowserifyを持っていても "require not defined"と表示されるエラーです。

これを修正する方法はありますか?または、他の方法で時間を稼ぐことができますか、カーボンのdifffromhumanのようなものですか?

+0

WebpackやBrowserifyのようなビルドシステムを使用していますか? – motanelu

+0

この[質問](http://stackoverflow.com/questions/34308004/moment-js-with-vuejs)を見て、[vue-moment](https://github.com/brockpetrie/vue)を見てください。 - モーメント)プロジェクト。 – VincenzoC

+0

私はまだそれを試してみるつもりはなかった – Christian

答えて

0

テンプレート内のコンテキストには、Vueのデータで宣言されている変数しかありません。あなたのオプションは以下の通りです:

  1. あなたのVueのデータに瞬間のリファレンスを追加してください。
  2. モーメント計算を行う方法をあなたのVueに追加します。
  3. あなたのための瞬間計算を行う計算を追加してください。

最後の1つが推奨ルートです。