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?

4
  • Are you using a build system like Webpack or Browserify? Commented Feb 17, 2017 at 14:51
  • See this question and take a look at the vue-moment project. Commented Feb 17, 2017 at 14:52
  • I still didn't Im gonna try it now Commented Feb 17, 2017 at 14:53
  • @motanelu tried using browserify but it still doesnt work Commented Feb 17, 2017 at 15:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.