Code Monkey home page Code Monkey logo

vue-fragment's Introduction

vue-fragment npm version


Disclaimer

To all enthousiasts and users of this package, first, thank you. I'm quite busy since i've published 1.5.0 and totally let go of this repo. I know it sucks, but we're all busy from time to time, right? If someone is interested in taking lead on this, please open an issue or contact me. I'd be more than happy if someone would feel helping until Vue 3 comes up.

Cheers to all, J.


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

From here, you can:

  • Plugin:

    import Fragment from 'vue-fragment'
    Vue.use(Fragment.Plugin)
    
    // or
    
    import { Plugin } from 'vue-fragment'
    Vue.use(Plugin)
    
    // …
    
    export const MyComponent {
      template: '
      <fragment>
        <input type="text" v-model="message">
        <span>{{ message }}</span>
      </fragment>
      ',
      data() { return { message: 'hello world }}
    }
    
  • Component:

    import { Fragment } from 'vue-fragment'
    
    export const MyComponent {
      components: { Fragment },
      template: '
      <fragment>
        <input type="text" v-model="message">
        <span>{{ message }}</span>
      </fragment>
      ',
      data() { return { message: 'hello world }}
    }
    

vue-fragment's People

Contributors

y-nk avatar davidreinberger avatar cyrilkrylatov avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.