0

I'm using laravel and this is my vue

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

                }
            }

        });

and here is my view

   <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>

I want to get my created at column in the view and use the fromnow function of moment.js and I've tried to look for solutions but they don't work for me.

I used required('moment') but this is always the error I'm getting "require is not defined" even having the browserify installed via npm install -g browserify.

Do you guys have any way to fix this? or any other method to get the fromnow time or like the carbon's difffromhuman?

Christian
  • 417
  • 1
  • 5
  • 11

1 Answers1

0

The context from within templating is only going to have variables that are declared on the Vue's data. Your options are:

  1. Add a reference to moment to your Vue's data.
  2. Add a method to your Vue that will do the moment calculation for you.
  3. Add a computed to do the moment calculation for you.

The last one is the recommended route.

David K. Hess
  • 16,632
  • 2
  • 49
  • 73