Skip to content

Instantly share code, notes, and snippets.

@lee-chase
Created March 1, 2019 20:24
Show Gist options
  • Save lee-chase/b953b5b54b6ab58f09f092b80d01a398 to your computer and use it in GitHub Desktop.
Save lee-chase/b953b5b54b6ab58f09f092b80d01a398 to your computer and use it in GitHub Desktop.
vue insert element
// inserts an element directly in place with no wrapper element
import Vue from 'vue';
export default {
name: 'CvuInsertElement',
functional: true,
props: ['html'],
render(h, ctx) {
const node = new Vue({
template: `${ctx.props.html}`
}).$mount()._vnode;
// add attributes
for (let attr in ctx.data.attrs) {
if (!node.data.attrs[attr]) {
node.data.attrs[attr] = ctx.data.attrs[attr];
}
}
// merge classes
node.data.class = (ctx.data.class || '') + ' ' + (ctx.data.staticClass || '');
return node;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment