Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nl2br for vue3
// Adapted from https://github.com/inouetakuya/vue-nl2br/
{
props: {
tag: {
type: String,
required: true,
},
text: {
type: String,
required: true,
},
className: {
type: String,
required: false,
},
},
setup(props) {
return () =>
Vue.h(
props.tag,
{
'class': props.className
},
props.text.split('\n').reduce((accumulator, string) => {
if (!Array.isArray(accumulator)) {
return [accumulator, Vue.h('br'), string]
}
return accumulator.concat([Vue.h('br'), string])
})
);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.