Created
March 1, 2019 20:24
-
-
Save lee-chase/b953b5b54b6ab58f09f092b80d01a398 to your computer and use it in GitHub Desktop.
vue insert element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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