gpt4 book ai didi

javascript - ReactJS 中的全局函数告诉我 'not a function'

转载 作者:行者123 更新时间:2023-11-30 09:15:42 25 4
gpt4 key购买 nike

<分区>

我有一个 GlobalFunction.js 文件。

function day(day) {
switch(day) {
case 0:
return "Sunday";
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
}
}
function month(month) {
switch(month) {
case 0:
return "January";
case 1:
return "February";
case 2:
return "March";
case 3:
return "April";
case 4:
return "May";
case 5:
return "June";
case 6:
return "July";
case 7:
return "August";
case 8:
return "September";
case 9:
return "October";
case 10:
return "November";
case 11:
return "December";
}
}
function styleTime(time) {
time = time[1].split(':');
// fetch
var hours = Number(time[0]);
var minutes = Number(time[1]);
var seconds = Number(time[2]);
// calculate
var timeValue;
if (hours > 0 && hours <= 12) {
timeValue= "" + hours;
} else if (hours > 12) {
timeValue= "" + (hours - 12);
} else if (hours == 0) {
timeValue= "12";
}

timeValue += (minutes < 10) ? ":0" + minutes : ":" + minutes; // get minutes
timeValue += (hours >= 12) ? " P.M." : " A.M."; // get AM/PM
return timeValue;
}
function nth(d) {
if (d > 3 && d < 21) return 'th';
switch (d % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
function styleDate(date) {
var verifyDay = new Date(date[0]);
var dayOfWeek = day(verifyDay.getDay()); //prints monday, tuesday, wednesday, etc
var year = verifyDay.getFullYear(); // prints the year
var month = month(verifyDay.getMonth());
var day = verifyDay.getDate();
var date = day + nth(verifyDay.getDate());
return dayOfWeek + ", " + month + " " + date + " " + year;
}

export function styleDateTime(dateString) {
var dateTime = dateString.split(" ");
return styleDate(dateTime) + " at " + styleTime(dateTime);
}

// default export
export default function() {
return 'default';
}

我像这样将其导入到 js 文件中。

import { styleDateTime } from "../GlobalFunctions"

我是这样使用的:

{styleDateTime(array.date)}

在 styleDate 函数中,它告诉我 day 不是一个函数。为什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com