Registry / web-framework / vue-hooks-plus

vue-hooks-plus

JSON →
library2.4.3jsnpmunverified

VueHooks Plus is a high-performance and simple library offering a comprehensive collection of Vue 3 composition API hooks. It is currently stable at version 2.4.3 and demonstrates an active development cadence with frequent minor and patch releases. Key differentiators include its robust `useRequest` hook for powerful request management, full TypeScript support with predictable static types, SSR compatibility, and support for on-demand loading and auto-imports via resolvers like `@vue-hooks-plus/resolvers`. The library aims to provide a rich set of utilities for common Vue development patterns, promoting reusability and simplifying complex logic within Vue 3 applications.

npm install vue-hooks-plus
INSTALL
IMPORT
SIG · VUE-HOOKS-PLUS
V
vue-hooks-plus
web-frameworkjavascriptv2.4.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useRequest
import { useRequest } from 'vue-hooks-plus'
const { useRequest } = require('vue-hooks-plus')
Primary import for the powerful data fetching hook. The library is ESM-first, so CommonJS `require` is incorrect for direct imports.
useLocalStorage
import { useLocalStorage } from 'vue-hooks-plus'
import useLocalStorage from 'vue-hooks-plus/es/useLocalStorage'
While on-demand imports were previously shown, the recommended approach for most hooks is named import from the main package. The 'es/' path is for specific advanced bundling cases.
VueHooksPlusResolver
import { VueHooksPlusResolver } from '@vue-hooks-plus/resolvers'
import { VueHooksPlusResolver } from 'vue-hooks-plus'
This resolver is used with `unplugin-auto-import` for automatic hook imports and comes from a separate, companion package.

This example demonstrates how to use the `useRequest` hook to fetch data, handle loading and error states, and dynamically change parameters, including polling.

import { ref } from 'vue' import { useRequest } from 'vue-hooks-plus' interface UserData { id: number; name: string; email: string; } // Simulate an API call const fetchUser = async (userId: number): Promise<UserData> => { console.log(`Fetching user with ID: ${userId}`) await new Promise(resolve => setTimeout(resolve, 1000)) if (userId === 1) { return { id: 1, name: 'John Doe', email: 'john@example.com' } } else if (userId === 2) { throw new Error('User not found') } else { return { id: userId, name: `User ${userId}`, email: `user${userId}@example.com` } } } // A basic Vue component using useRequest export default { setup() { const currentUserId = ref(1) const { data, loading, error, run, cancel } = useRequest( () => fetchUser(currentUserId.value), { refreshDeps: [currentUserId], pollingInterval: 5000, // Poll every 5 seconds manual: false, // Automatically run on mount/deps change onError: (e) => console.error('Request error:', e.message) } ) const fetchNextUser = () => { currentUserId.value++ } return { data, loading, error, fetchNextUser, cancel, currentUserId } }, template: ` <div> <h1>User Data with useRequest</h1> <p>Current User ID: {{ currentUserId }}</p> <div v-if="loading">Loading user...</div> <div v-else-if="error">Error: {{ error.message }}</div> <div v-else-if="data"> <p>ID: {{ data.id }}</p> <p>Name: {{ data.name }}</p> <p>Email: {{ data.email }}</p> </div> <button @click="fetchNextUser">Fetch Next User</button> <button @click="cancel">Cancel Request</button> </div> ` }
Debug
Known issues
breakingIn `v2.3.1`, the internal dependency `lodash` was replaced with `lodash-es`. While this generally improves bundle size and tree-shaking, direct imports from `lodash` within your project, if any, may need to be updated to `lodash-es` or refactored.
fix
Review project dependencies and imports. If directly using lodash functionality, ensure you are importing from `lodash-es` for tree-shaking benefits or update your import paths.
affects: >=2.3.1
gotchaWhen using auto-import features, ensure you have correctly installed and configured `@vue-hooks-plus/resolvers` with `unplugin-auto-import`. Misconfiguration can lead to 'hook not found' errors or incorrect global availability.
fix
Verify that `unplugin-auto-import` and `@vue-hooks-plus/resolvers` are installed as dev dependencies, and that your `vite.config.ts` or `webpack.config.js` includes the correct resolver configuration as shown in the documentation.
affects: >=2.0.0
gotchaThe `useRequest` hook in `v2.4.0` introduced support for concurrent requests. While this is an enhancement, developers relying on previous sequential request behaviors in complex scenarios might need to review their usage patterns to ensure expected behavior.
fix
Thoroughly test `useRequest` implementations in environments with potential concurrent requests after upgrading to `v2.4.0` to ensure no unexpected side effects or race conditions arise, especially in scenarios where state mutation order is critical.
affects: >=2.4.0
Errors
Common errors & fixes
TypeError: (0 , vue_hooks_plus__WEBPACK_IMPORTED_MODULE_2__.useRequest) is not a function
Attempting to use CommonJS `require` syntax or incorrect named import destructuring for a library that primarily exports ES Modules.
fix
Ensure you are using ES Module import syntax: `import { useRequest } from 'vue-hooks-plus'` in a module-aware environment (e.g., modern Vite/Webpack setup).
Cannot find name 'useRequest'. Did you mean 'Request'?
TypeScript or IDE cannot find the hook, often due to missing type definitions or incorrect auto-import configuration.
fix
If manually importing, ensure `import { useRequest } from 'vue-hooks-plus'` is present. If using auto-import, verify `@vue-hooks-plus/resolvers` is correctly configured in your build tool and that `src/auto-imports.d.ts` (or similar) has been generated.
Property 'value' does not exist on type '(...args: any[]) => Promise<any>'
Attempting to access `.value` on a non-ref object returned by a hook, typically in a reactive context, or incorrectly typing a reactive variable.
fix
Ensure that reactive variables (like those returned by `ref`, `computed`, or some hook properties) are explicitly unwrapped or accessed with `.value` where appropriate, especially within `<script setup>` or template expressions where auto-unwrapping might not apply.
Upgrade
Version history
2.4.3latest on npm
Audit
Dependencies
vuerequiredPeer dependency required for all Vue 3 projects using this library.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vue-hooks-plus — npm install vue-hooks-plus · libregistry