[Vuejs]-How to pass a string in Vue and have it treated as html

2πŸ‘

βœ…

Any value given to input tag (also textarea) will be treated as a string.
To show channel name in the textarea tag, you can do this

computed: {
    channel: {
        get() {
            const selectedChannel = this.$store.getters.selectedChannel;
            // using regex to match the text between "b" tag
            const channelName = selectedChannel.match("<b\b[^>]*>(.*?)<\/b>")[1];
            return selectedChannel ? `<textarea>${channelName}</textarea>` : '';
        }

In template:

<div class="channels" v-html="channel">
</div>

0πŸ‘

I think you are looking for the β€˜v-html’ directive

πŸ‘€Austio

0πŸ‘

You need to use the v-html directive:

<div class="channels" v-html="channel">
</div>

Sample fiddle here

πŸ‘€Gus

Leave a comment