首页 > 解决方案 > 方法“showDate”在组件定义中具有“未定义”类型

问题描述

我在 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”在组件定义中具有类型“未定义”。您是否正确引用了该函数?如何正确定义以在模板 HTML 中使用它?

标签: javascriptvue.js

解决方案


看来您错过了“changeFormatDate.js”中的导出

https://javascript.info/import-export


推荐阅读