Vue
HTML
<div id='app'>
<trial></trial>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
const Fragment = {
install(Vue) {
// install the teleporter
Vue.directive('fragment', {
inserted(element) {
const fragment = document.createDocumentFragment();
Array.from(element.childNodes).forEach(child => fragment.appendChild(child));
element.parentNode.insertBefore(fragment, element);
element.parentNode.removeChild(element);
}
})
Vue.component('vue-fragment', {
template: `<div v-fragment><slot /></div>`
})
}
}
Vue.use(Fragment);
Vue.component('trial', {
template: `
<vue-fragment>
<span>{{ message }}</span>
<input type="text" v-model="message" />
</vue-fragment>
`,
data() { return {
message: 'hello world'
}}
})
new Vue({ data() { return {
message: 'hello world'
}}}).$mount('#app')