nl2br pour Vue3

J’ai voulu utiliser nl2br pour vue.js mais il n’est pas compatible avec Vue3.

Voici mon adaptation

// 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])
                })
            );
    },
};Langage du code : JavaScript (javascript)

Les commentaires sont fermés.