Code Monkey home page Code Monkey logo

vue-transfer-dom's Introduction

vue-transfer-dom

requires Vue v1.0.19+

Transfer DOM to another place (eg. <body>).

Useful in some situations such as z-index management, see discussion here.

Demo (prevent modal overlap by other elements)

http://jsfiddle.net/rhyzx/br5cepu3/

Installation

npm install vue-transfer-dom

Usage

Vue.use(VueTransferDom /*, {name: 'transferDom'}*/)

new Vue({
  template: '<div v-transfer-dom>foo</div>', // div will be appended to body(default)
})

// append to specific place
new Vue({
  template: '<div v-transfer-dom:bar>foo</div>', // div will be appended to #bar(document.getElementById)
})

vue-transfer-dom's People

Contributors

kazupon avatar rhyzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-transfer-dom's Issues

Better support for usage inside the component template

Consider the following example, where we can have the v-transfer-dom directive applied to the main template element of the modal component directly, so it will always transfer the modal to the body without having to explicitly use the directive on the modal component:

http://jsfiddle.net/lazabogdan/wobmzd87/

The example above works only in combination with v-if applied to the main template element of the modal component. If you'd replace v-if with v-show, it won't work and v-if feels more like a hack to make this work.

Let me know what you think.

Conflict with Vue.mixin

Vue has a syntax for defining global mixins, Vue.mixin({ ... }). Some libraries use it to inject global hooks into components.

Now, if Vue.mixin was ever applied before Vue.use(VueTransferDom), then a runtime error appears.
But If Vue.mixin is applied after Vue.use(VueTransferDom), then the error goes away.

Repro: https://jsfiddle.net/ujafg3js/1/

transferred element loses dom event bindings

Clicking on the button or image fails to trigger the event handler.

root

<template>
  <div id="root"></div>
</template>

components/complex-button

<template>
  <a class="complex-button"><slot></slot></a>
</template>

states/a-page

<template>
  <div class="state__some-page">
    <header>Page Title</header>
    <article>
      <complex-button
        v-transfer-dom:root
        v-on:click="foo">Foo</complex-button>

      <img src="//placehold.it/50x50"
        v-transfer-dom:root
        v-on:click="foo"
        alt="a root transferred image">

    </article>
    <footer></footer>
  </div>
</template>
<script>
export default {
  methods: {
    foo () {
      console.log('bar');
    }
  }
};
</script>

Attribute "v-transfer-dom" is ignored

I get this warning when using this attribute on production. On local environment I don't see this warnings.

[Vue warn]: Attribute "v-transfer-dom" is ignored on component because the component is a fragment instance

I also tried to use it on a root element but then I get this:

v-transfer-dom="" cannot be used on an instance root element.

Image

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.