方法“ showDate”在组件定义中的类型为“未定义”

时间:2020-02-28 10:20:13

标签: javascript vue.js

我已经在changeFormatDate.js文件中编写了一些日期处理实用程序,用于格式化日期时间,

 'changeFormatDate.js'   

 const showDate = function (d) {
return moment(d).format("DD/MM/YYYY");
 }

,并且我尝试在HTML模板中呈现此功能。

 'template.vue'
       <template lang="pug">
              .data(v-for="(rata,index) in loan.schedule")
                  .values
                      span {{index+1}}
                      span {{showDate(rata.date)}}
   </template>

  <script>
    import { showDate } from "@/util/changeFormatDate.js";
    import moment from "moment";

    export default {
       name: "TimetableApplication",
       props: {
       loan: { type: Object, required: true }
 },
    methods: {
     showDate
  }
};
</script>

但是仍然出现错误“方法“ showDate”在组件定义中的类型为“ undefined”。您是否正确引用了该函数?如何正确定义以在模板HTML中使用它?

1 个答案:

答案 0 :(得分:2)

似乎您错过了“ changeFormatDate.js”中的导出

https://javascript.info/import-export