【问题标题】:moment js fromnow function to vue js laravel时刻 js fromnow 函数到 vue js laravel
【发布时间】:2017-07-07 03:29:06
【问题描述】:

我正在使用 laravel,这是我的 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;
                    });

                }
            }

        });

这是我的看法

   <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'),但这始终是我得到的错误“require is not defined”,即使通过 npm install -g browserify 安装了 browserify。

你们有什么办法解决这个问题吗?或任何其他方法来获取从现在开始的时间或像碳的 difffromhuman 一样?

【问题讨论】:

  • 你在使用像 Webpack 或 Browserify 这样的构建系统吗?
  • 查看此question 并查看vue-moment 项目。
  • 我还是没有我现在要试试
  • @motanelu 尝试使用 browserify 但仍然无法正常工作

标签: javascript laravel vue.js momentjs


【解决方案1】:

模板中的上下文只会包含在 Vue 数据上声明的变量。您的选择是:

  1. 为您的 Vue 数据添加对时刻的引用。
  2. 向您的 Vue 添加一个方法,该方法将为您计算矩。
  3. 添加一个计算来为您进行矩计算。

最后一条是推荐路线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 2021-07-11
    相关资源
    最近更新 更多