1.0.17 • Published 5 months ago

ndjjd-utils v1.0.17

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

南岛聚集地 工具包- 待修改

快速开始

npm install ndjjd-utils --save

例如在vue的项目中使用:

<template>
    <component :is="importComponent(componentId)"></component>
</template>
<script lang="ts" setup>
//  importComponent 函数 参数未组件ID,返回一个vue的异步组件
import { importComponent } from 'ndjjd-utils';
const componentId = ref("组件ID");
</script>

上述方式会从远程服务器拉取一个Vue的组件,进行渲染;

在ts或者js中使用工具函数类的包时,例如:

import { importModule, load, importAsyncModule } from 'ndjjd-utils'

/**
 * 组件内容包括
 * {
 *  id: string; 组件ID
 *  name: string; 组件中文名称 比如 "测试包"
 *  module: string; 组件在项目中使用名称比如 "TestUtils"
 * }
 */
// 可以在main.js 入口处,统一加载远程组件
await load(["组件ID"]);

// 使用包
// importAsyncModule 未异步获取包
// const testUtils = await importAsyncModule("@Ndd/TestUtils");
const testUtils = importModule("@Ndd/TestUtils");

/**
 * 假如 TestUtils 导出了一个helloWorld函数 例如
 *
 * export function helloWorld(name){
 *  console.log("helloWorld: " + name);
 * }
 */
testUtils.helloWorld("南岛聚集地"); // 输出 helloWorld: 南岛聚集地

addDependencies的使用 在编译组件的实际应用中,可能不想把所有的依赖都打入到组件中。这样的组件。在使用之前需要把组件注入到我们的库中

/**
 * 当我们编译的组件。忽略了某些包的时候,例如 有一个 api的包
 * import axios from 'axios';
 *
 * export function getData(){
 *  return axios.get("/api");
 * }
 *
 * 例如这样的代码编译之后。忽略了axios
 */
// main.js
// 注意假如到我们的依赖中 必须使用 * as name 这样的导入方式,这样不会漏掉一些非default的函数或类
import * as axios from 'axios';
import {addDependencies, load} from 'ndjjd-utils';
addDependencies([
  {
    // name未原有包的名称
    name: "axios",
    module:axios
  }
])

await load("组件ID");

// vue 中
import { importModule, } from 'ndjjd-utils'
const {getData} = importModule("@ndd/api");
getData().then(res=>{
  console.log(res);
})
1.0.2

8 months ago

1.0.1

8 months ago

1.0.17

5 months ago

1.0.0

8 months ago

1.0.16

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

8 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.15

5 months ago

1.0.14

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

0.0.36

12 months ago

0.0.35

12 months ago

0.0.34

12 months ago

0.0.32

12 months ago

0.0.31

12 months ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago