【已解决】React 创建工具集

1.创建工具集

let Util = {
    sayHello(){
        console.log('hello');
    },

    sayWorld(){
        return 'world';
    }
}

export default Util;

2.调用工具

// 先使用 import 导入工具集文件
import Util from './util/Util.jsx';

// 在通过 Util.method() 即可调用
Util.sayHello();
console.log(Util.sayWorld());

// 输出
hello
world

以上。

猜你喜欢

转载自blog.csdn.net/Ja_time/article/details/89451714
今日推荐