我在dateTime.js中创建了可重用的代码:
import { ref, computed, watch } from 'vue';
import * as dayjs from 'dayjs';
export default function dateTime() {
const newDateTimeString = ref(null);
function showDateTime(data) {
const dateTime = dayjs(data).format('DD-MM-YYYY')
newDateTimeString.value = dateTime;
}
return {
newDateTimeString,
showDateTime
}
}
在Table.vue中调用了dateTime.js中的代码:
问题:我该如何使其工作?我想在模板中使用{{ showDateTime(scope.row[itemIn.field]) }}。在我看来,这应该最终触发dateTime.js中的showDateTime函数。
我做错了什么?错误代码:Uncaught (in promise) TypeError: Object(...) is not a function,它指的是const { showDateTime } = useDateTime();
<template v-else-if="itemIn.type == 'dateTime'">
{{ showDateTime(scope.row[itemIn.field]) }}
</template>
<script>
import { ref, computed } from 'vue';
import { defineComponent } from "vue";
import { useStore } from "vuex";
import { useDateTime } from '@/composables/dateTime';
export default defineComponent({
name: "",
props: {
processingData: Object
},
components: {
Flag
},
emits: ["unique", "refresh"],
setup(props, {emit}) {
const { showDateTime } = useDateTime();
const store = useStore()
function setStatus(id, route) {
const object = {
id: id,
route: route
}
return store.getters.getStatus(object);
}
return {
getScope,
setUniqueId,
getClass,
getWidth,
navigatePagination,
setStatus,
setTag,
showDateTime
};
}
});
</script>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
当你使用
export default导出useDateTimehook时,你必须在导入时不使用{ }: