vite-plugin-v-if-model
v0.0.1
Published
Vite plugin to transform `v-if-model` to `v-if` + `v-model` + `:key` at compile time.
Maintainers
Readme
vite-plugin-v-if-model
🧩 A Vite plugin that adds a custom v-if-model directive for Vue 3 — auto-expands to v-if, v-model, and :key, helping components (like dialogs) re-render correctly when visibility changes.
✨ Features
- ✅ Replaces
v-if-modelwithv-model,v-if, and:key - ✅ Supports arguments and modifiers (e.g.,
v-if-model:visible.lazy) - ✅ Designed for Vue 3 + Vite
- ✅ Great for conditionally rendered components like dialogs
📦 Installation
npm i vite-plugin-v-if-model -Dor
pnpm add vite-plugin-v-if-model -D🛠 Usage
- Add to vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vIfModel from 'vite-plugin-v-if-model'
export default defineConfig({
plugins: [
vue(),
vIfModel(), // register here
],
})- Use v-if-model in Vue templates
<template>
<Dialog v-if-model="dialogVisible" />
</template>
<script setup>
import { ref } from 'vue'
const dialogVisible = ref(false)
</script>Will compile to:
<Dialog
v-model="dialogVisible"
v-if="dialogVisible"
:key="'vifmodel_' + (dialogVisible)"
/>- Supports arguments and modifiers
<Dialog v-if-model:visible.lazy.trim="dialogVisible" />Expands to:
<Dialog
v-model:visible.lazy.trim="dialogVisible"
v-if="dialogVisible"
:key="'vifmodel_' + (dialogVisible)"
/>