Make pinia easy to use and has intelisense.

Overview

pinia-auto-refs

NPM version NPM downloads

Pinia Auto Refs on-demand for Vite. With TypeScript support. Powered by unplugin-auto-import.Inspiration by vieruuuu in pinia/issues#718.

掘金:受够了手动 storeToRefs?来试试这个 vite 插件吧

without

import useUserStore from '@/store/user'

const userStore = useUserStore()
const { name, token, fullName } = storeToRefs(userStore)
const { updateName } = userStore

with

const { name, token, fullName, updateName } = useStore('user')

Install

npm i pinia-auto-refs

Setup

// 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(),
  ],
})

Config Options

type Options = Partial<{
  storeDir: string
  excludes: string[]
  outputFile: string
}>

const defaultOptions = {
  storeDir: 'src/store',
  excludes: ['index'],
  outputFile: 'src/helper/pinia-auto-refs.ts',
}

Attentions

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',
  /* ... */
})
You might also like...

Nuxt.js module to use Unleash toggle feature services

nuxt-unleash Nuxt.js module to use Unleash toggle feature services 📖 Release Notes Features Use $unleash to access and handle your Unleash feature fl

Dec 3, 2022

We open the tools we use in our projects to all developers.

huntersofbook This repo was created with the aim of developing the vue ecosystem as well as giving back to the open-source world what we learned from

Dec 27, 2022

Nuxt-Module, that provides a system to set shopware cache-tags for later use in e.g. a full-page cache

nuxt-shopware-caching Nuxt-Module, that provides a system to set shopware cache-tags for later use in e.g. a full-page cache. This module is meant to

Nov 8, 2022

Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

Onsen UI - Cross-Platform Hybrid App and PWA Framework Onsen UI is an open source framework that makes it easy to create native-feeling Progressive We

Jan 4, 2023

Backs up your favourite and recently used gifs/emotes and restores them in case discord clears them after logouts or for other reasons

Persist Favourites This plugin solves the problem of Discord randomly deciding to clear your gifs or emotes by backing both up regularely and restorin

Oct 13, 2022

Based on vitawind, kowind brings ESLint plugin and some other plugins to it that help you to format your code quickly and efficiently.

🐦 KOWIND v3 🐦 Vite helper based on vitawind 🧰 Easy To Install ⚡️ Automatically open Tailwind JIT Mode ⚙ One-Command Setting 🚀 Automatically config

Nov 26, 2022

Morse code is a method used in telecommunication to encode text characters as standardized sequences of two different signal durations, called dots and dashes, or dits and dahs.

@elonehoo/point-line Install # npm npm i @elonehoo/point-line # yarn yarn add @elonehoo/point-line #pnpm pnpm i @elonehoo/point-line Usage import {dec

Aug 3, 2022

NativeScript empowers you to access native api's from JavaScript directly. Angular, Vue, Svelte, React and you name it compatible.

NativeScript empowers you to access native api's from JavaScript directly. Angular, Vue, Svelte, React and you name it compatible.

NativeScript empowers you to access native APIs from JavaScript directly. The framework currently provides iOS and Android runtimes for rich mobile de

Jan 4, 2023
Comments
  • action含有异步操作时,会报错

    action含有异步操作时,会报错

    如题

    actions:{
      setUserInfo(userInfo) {
          Object.assign(this.userInfo, userInfo)
      },
     async getUserInfo() {
        const { permissions, roles, user } = (await getUserInfo()) as {permissions:string[],roles:string[],user:IUserInfo}
        this.setUserInfo(user)
      }
    }
    

    在使用useStore的地方报错如下:

    helper_piniaAutoRefs.useStore is not a function
    

    注释掉异步方法就不再报错

    opened by H-Haynes 2
Veloce: Starter template that uses Vue 3, Vite, TypeScript, SSR, Pinia, Vue Router, Express and Docker

Veloce Lightning-fast cold server start Instant hot module replacement (HMR) and dev SSR True on-demand compilation Tech Stack Vue 3: UI Rendering lib

Alan Morel 10 Oct 7, 2022
Third-Party Authentication (Github) demo Vue 3 + TypeScript + Pinia app using Supabase

vue-supabase-tpa-demo This template should help get you started developing with Vue 3 in Vite. Recommended IDE Setup VSCode + Volar (and disable Vetur

Mac (Maciej Pędzich) 25 Nov 21, 2022
A template to use GoLang Lorca package to make desktop applications using webview and Svelte for the frontend,

Svelte Lorca Template A starter project for building modern cross-platform desktop apps in Go, HTML, and Svelte. This project is a fork of lorca-ts-re

Ben Winchester 16 Jun 19, 2022
Make use css module more sense.

vite-plugin-sense-css-module Make use css module more sense. Installation npm npm install --save-dev vite-plugin-sense-css-module yarn yarn add -D vi

null 2 Sep 25, 2022
Matteo Bruni 4.7k Jan 4, 2023
Make your Vite projects work in IE11 and other legacy browsers.

vite-plugin-legacy-dev Maybe your Vite project needs work on IE11 or other not support ESM legacy browsers, this plugin can help you! This is only for

haiya6 3 Sep 26, 2022
:necktie: :briefcase: Build fast :rocket: and easy multiple beautiful resumes and create your best CV ever! Made with Vue and LESS.

best-resume-ever ?? ?? Build fast ?? and easy multiple beautiful resumes and create your best CV ever! Made with Vue and LESS. Cool Creative Green Pur

Sara Steiert 15.8k Jan 9, 2023
Make Phaser 3 games with modern frontend tooling.

Phaser 3 + Vite.js Template Make Phaser 3 games with modern frontend tooling. Prerequisites You'll need Node.js and npm installed. It is highly recomm

ourcade 15 Dec 15, 2022
Easy generation of OpenGraph & Twitter meta-tags in Nuxt 3 📋

nuxt-social-tags Easy generation of OpenGraph & Twitter meta-tags in Nuxt 3 ✨ Release Notes ?? Read the documentation Features Nuxt3 ready Composables

Conner 19 Dec 17, 2022
This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configured and ready to use in real world projects!

Nuxt 3 Starter This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configure

Ali Soueidan 26 Dec 27, 2022