{"id":13691897,"url":"https://github.com/uni-helper/uni-use","last_synced_at":"2025-04-09T14:15:38.175Z","repository":{"id":63284842,"uuid":"566663261","full_name":"uni-helper/uni-use","owner":"uni-helper","description":"uni-app (vue3) 组合式工具集","archived":false,"fork":false,"pushed_at":"2024-04-15T01:52:44.000Z","size":1336,"stargazers_count":97,"open_issues_count":2,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-17T04:55:10.893Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uni-helper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ModyQyW","KeJunMao","Neil Lee"],"custom":["https://afdian.net/a/kejun","https://github.com/ModyQyW/sponsors","https://afdian.net/a/zguolee"]}},"created_at":"2022-11-16T06:30:29.000Z","updated_at":"2024-06-14T11:32:25.864Z","dependencies_parsed_at":"2024-03-16T02:40:47.897Z","dependency_job_id":"4d545e4f-c49b-462e-adef-b9fdc15e434a","html_url":"https://github.com/uni-helper/uni-use","commit_stats":{"total_commits":102,"total_committers":1,"mean_commits":102.0,"dds":0.0,"last_synced_commit":"a8040917a5432684e0b073b4703c145c0ce24a90"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Funi-use","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Funi-use/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Funi-use/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Funi-use/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uni-helper","download_url":"https://codeload.github.com/uni-helper/uni-use/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819774,"owners_count":20839095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T17:00:51.428Z","updated_at":"2025-04-02T13:06:43.648Z","avatar_url":"https://github.com/uni-helper.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ModyQyW","https://github.com/sponsors/KeJunMao","https://github.com/sponsors/Neil Lee","https://afdian.net/a/kejun","https://github.com/ModyQyW/sponsors","https://afdian.net/a/zguolee"],"categories":["TypeScript","Lib 工具库"],"sub_categories":[],"readme":"# @uni-helper/uni-use\n\n[![License](https://img.shields.io/github/license/uni-helper/uni-use)](https://github.com/uni-helper/uni-use/blob/main/LICENSE)\n[![npm](https://img.shields.io/npm/v/@uni-helper/uni-use)](https://www.npmjs.com/package/@uni-helper/uni-use)\n\n`uni-app (vue3)` 组合式工具集。要求 `node\u003e=18`。\n\n- [@uni-helper/uni-use](#uni-helperuni-use)\n  - [安装依赖](#安装依赖)\n  - [使用](#使用)\n  - [其它](#其它)\n    - [限制](#限制)\n    - [构建](#构建)\n    - [和 `unplugin-auto-import` 结合使用](#和-unplugin-auto-import-结合使用)\n    - [EventBus](#eventbus)\n    - [TypeScript](#typescript)\n  - [资源](#资源)\n  - [致谢](#致谢)\n\n## 安装依赖\n\n```shell\nnpm install @uni-helper/uni-use @vueuse/core@9\n```\n\n如果你希望使用 `@vueuse/core` v10，请参考 [uni-app#4604](https://github.com/dcloudio/uni-app/issues/4604)。\n\n\u003cdetails\u003e\n  \u003csummary\u003eyarn v2 或以上\u003c/summary\u003e\n  \u003cp\u003e请参考 \u003ca href=\"https://yarnpkg.com/configuration/yarnrc/#nodeLinker\"\u003e文档\u003c/a\u003e 设置 \u003ccode\u003enodeLinker\u003c/code\u003e 为 \u003ccode\u003enode_modules\u003c/code\u003e。\u003c/p\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003epnpm\u003c/summary\u003e\n  \u003cp\u003e请参考 \u003ca href=\"https://pnpm.io/npmrc#shamefully-hoist\"\u003e文档\u003c/a\u003e 设置 \u003ccode\u003eshamefully-hoist\u003c/code\u003e 为 \u003ccode\u003etrue\u003c/code\u003e。\u003c/p\u003e\n\u003c/details\u003e\n\n目前没有支持 `uni_modules` 的计划，但欢迎 PR 贡献。\n\n## 使用\n\n详情请看 [`uni-use`函数列表](./src/index.md)\n\n## 其它\n\n### 限制\n\n在小程序和移动应用环境下有如下无法避开的限制：\n\n- 缺失某些全局变量（如 `window`、`navigator` 等）\n- 必须使用 `uni-app` 提供的 API 实现功能（如拦截器、存储等），API 不支持的也就无法支持，比如拦截同步 API、监听其它地方引起的剪切板变化等\n- 无法使用顶层 `await`\n\n在开发网页时，建议直接使用 `vue`，避免过多的环境判断代码，同时也能享受更好的生态，如 `vueuse` 的完整支持。\n\n### 构建\n\n目前 `@uni-helper/uni-use` 会使用 `unbuild` 将 `uni` API 之外的部分转译到 `ES2017`（即 `ES8`）。`uni` API 需要在项目构建时由 `uni-app` 官方提供的插件处理。\n\n对于 `vite + vue3` 项目，请先设置 `build.target` 为 `ES6`。\n\n```typescript\nimport uni from '@dcloudio/vite-plugin-uni';\nimport { defineConfig } from 'vite';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  build: {\n    target: 'es6',\n    cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget\n  },\n  optimizeDeps: {\n    exclude: ['vue-demi'],\n  },\n  plugins: [\n    // ...,\n    uni(),\n    // ...,\n  ],\n});\n```\n\n然后在 `src/main.ts` 或 `src/main.js` 处自行添加 polyfill。以下是使用 [core-js](https://github.com/zloirock/core-js) 的示例（需要自行安装 `core-js`），你也可以使用 [es-shims](https://github.com/es-shims)。\n\n```typescript\nimport 'core-js/actual/array/iterator';\nimport 'core-js/actual/promise';\nimport 'core-js/actual/object/assign';\nimport 'core-js/actual/promise/finally';\n// 你可以根据需要自行添加额外的 polyfills\n// import 'core-js/actual/object/values'\nimport { createSSRApp } from 'vue';\nimport App from './App.vue';\n\nexport function createApp() {\n  const app = createSSRApp(App);\n  return {\n    app,\n  };\n}\n```\n\n微信小程序的 JavaScript 支持度见 [wechat-miniprogram/miniprogram-compat](https://github.com/wechat-miniprogram/miniprogram-compat)。微信小程序要支持 `vue3`，需设置基础库最低版本为 2.11.2 或以上，2.11.2 对应 `chrome\u003e=53,ios\u003e=10`。\n\n### 和 `unplugin-auto-import` 结合使用\n\n```typescript\n// vite.config.ts\nimport { fileURLToPath } from 'node:url';\nimport uni from '@dcloudio/vite-plugin-uni';\nimport { uniuseAutoImports } from '@uni-helper/uni-use';\nimport autoImport from 'unplugin-auto-import/vite';\nimport { defineConfig } from 'vitest/config';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  plugins: [\n    autoImport({\n      imports: [\n        uniuseAutoImports(),\n      ],\n    }),\n    uni({ /* ... */ }),\n  ],\n});\n```\n\n### EventBus\n\n如果你想使用 `EventBus`，请考虑使用 [VueUse - useEventBus](https://vueuse.org/core/useeventbus/#useeventbus)、[mitt](https://github.com/developit/mitt) 或 [nanoevents](https://github.com/ai/nanoevents)。这个库不再重复提供类似功能。\n\n### TypeScript\n\n`@uni-helper/uni-use` 本身使用 [TypeScript](https://www.typescriptlang.org/) 开发，拥有类型提示。\n\n## 资源\n\n- [改动日志](/CHANGELOG.md)\n\n## 致谢\n\n- [vueuse](https://vueuse.org/) [#1073](https://github.com/vueuse/vueuse/pull/1073)\n- [taro-hooks](https://taro-hooks-innocces.vercel.app/)\n- [tob-use](https://tob-use.netlify.app/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funi-helper%2Funi-use","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funi-helper%2Funi-use","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funi-helper%2Funi-use/lists"}