我想使用所有系统库或函数所在的外部.js文件。例如文件名sysFunction.js
import React from 'react';
function currYear() {
var year = new Date().getFullYear();
return year;
}
现在我调用此函数的文件
import React, { Component } from 'react';
import ReactDom from 'react-dom';`
import Logo from "../../../assets/app/media/img//logos/logo-1.png";
import sysFunction from "../SysFunctions/SysFunction";
export default class Login extends Component {
render(){
return({currYear()});
}
}
我的函数实际上驻留在另一个文件中,该文件通常不是组件文件。
答案 0 :(得分:2)
您可以尝试这样
import React from 'react';
export function currYear() {
var year = new Date().getFullYear();
return year;
}
import React, { Component } from 'react';
import ReactDom from 'react-dom';`
import Logo from "../../../assets/app/media/img//logos/logo-1.png";
import { currYear } from "../SysFunctions/SysFunction";
export default class Login extends Component
{
render(){
return({currYear()}
);
}
}