How do you guys deal with this scenario?
const renderTemplate = (template, obj) => {
const args = Object.keys(obj)
const body = `return (\`${template}\`)`
const renderFunc = new Function(...args.concat([body]))
return renderFunc(...Object.values(obj))
}
const dynamicallyLoadedTemplate = '${a} and ${b}'
console.log(
renderTemplate(dynamicallyLoadedTemplate, {
'a': '1',
'b': 2
})
)
Is this elegant enough?
checkout here: https://github.com/vuejs/vue/blob/dev/packages/vue-template-...
also checkout last 'state of Vue.js' on YT where the creator talks about it ;)