如何将moment.js导入vue

时间:2019-11-11 16:08:38

标签: date vue.js datepicker

我试图在一个非常简单的vue构建中使用moment.js。我已经在索引页面的主体中添加了moment.js,但是当我尝试使用moment.js时,却不断收到控制台错误“ ReferenceError:未定义矩”。

// registering the date picker
  components: {
    vuejsDatepicker,
},    


// the component with some props 
<vuejs-datepicker
                    :value="this.default"
                    name="datepicker"
                    :clear-button="true"
                    :typeable="true"
                    v-model="GetPaymentDate"
                    :format="customFormatter"
                    input-class="form-control"
                    ></vuejs-datepicker>

 methods: {

 // the method to produce formated date
    customFormatter(date) {
      return moment(date).format('MMMM Do YYYY, h:mm:ss a');
    }
},

// where Im trying to display formated date - this is the bit that breaks things - the | formatDate
<p>The delivery Date is <b>{{ GetPaymentDate | formatDate}}</b></p>


// the order of my scripts on the index file 
<script src="vue-moment.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"> . </script>
<script src="https://unpkg.com/vuejs-datepicker"></script>

1 个答案:

答案 0 :(得分:0)

只需添加以下行。您可以将其添加到main.js或组件文件中

从“片刻”导入时刻;