跳至主要內容

模块化如何封装

...小于 1 分钟

模块化如何封装

目录结构

|-- App.js
|-- utils
    |-- http.js
    |-- index.js

每个文件的代码

// http.js
class http {
    
}

export { http }
// index.js
import { http } from "./http";
export { http };
// App.js
import { http } from "@/utils";

基本思想就是, 将在一个文件夹下建各种功能的js文件, 由统一的 index.js 进行管理, 并导出

那么使用这个工具库的人就能按需, 导入模块使用

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.5