我已经在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中使用它?