vue-fragment-oxr
v2.6.6
Published
support to Vue3
Downloads
18
Maintainers
Readme
vue-fragment-oxr
NEW
Update support to Vue3, Minium Vue3 version is v2.7.0, test version by v3.3.4
the tag fragment
is update to VFragment(v-fragment)
what
a very candide fragment component for Vue.js
why
If you arrived here, I think you searched hard and you know why you're here.
For others, fragments are basically root-less components. They come useful in many situations where you don't want to pollute the DOM with a useless container, or you want to return many elements at once.
how
It's impossible to use functional components or slots, since Vue.js vDOM diffing has a "you should return one root element" limitation… Instead, I'm using an (internal) directive which will dump all the children of the fragment root node in its place. Since directives can manipulate DOM, we can act after rendering and bypass Vue limitation.
The component is called Fragment
so you won't have to change much code when Vue3 native fragments arrive. That said, I'm not a core developer of Vue.js, and I don't have any view of their implementation. I only know what fragments are and how they should work, and did my best to reproduce it ; so it should be fine.
use
- download the package
npm i -s vue-fragment-oxr
From here, you can:
Plugin:
import Fragment from 'vue-fragment-oxr' Vue.use(Fragment.Plugin) // or import { Plugin } from 'vue-fragment-oxr' Vue.use(Plugin) // … export const MyComponent { template: ' <v-fragment> <input type="text" v-model="message"> <span>{{ message }}</span> </v-fragment> ', data() { return { message: 'hello world }} }
Component:
import { VFragment } from 'vue-fragment-oxr' export const MyComponent { components: { VFragment }, template: ' <v-fragment> <input type="text" v-model="message"> <span>{{ message }}</span> </v-fragment> ', data() { return { message: 'hello world }} }