Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
pinia-auto-refs
Advanced tools
Pinia Auto Refs on-demand for Vite. With TypeScript support. Powered by unplugin-auto-import.Inspiration by vieruuuu in pinia/issues#718.
掘金:受够了手动 storeToRefs?来试试这个 vite 插件吧
Playground
import useUserStore from '@/store/user'
const userStore = useUserStore()
const { name, token, fullName } = storeToRefs(userStore)
const { updateName } = userStore
const { name, token, fullName, updateName } = useStore('user')
npm i pinia-auto-refs
// vite.config.ts
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import PiniaAutoRefs from 'pinia-auto-refs'
export default defineConfig({
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [
AutoImport({
imports: [
'pinia',
{
'@/helper/pinia-auto-refs': ['useStore'],
},
],
}),
PiniaAutoRefs(),
],
})
type Options = Partial<{
storeDir: string
excludes: string[]
outputFile: string
}>
const defaultOptions = {
storeDir: 'src/store',
excludes: ['index'],
outputFile: 'src/helper/pinia-auto-refs.ts',
}
You need to switch the store export mode to export default
, because we can't get what you exported directly when we import automatically. Using export default
makes it much easier.
// store/test.ts
export default defineStore({
id: 'test',
/* ... */
})
FAQs
Auto storeToRefs for use pinia state.
We found that pinia-auto-refs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.