i'm trying to achieve this. supposely i have data in backend with
example: this data - #ghost\n#mik\n#bro
supposedly it is store in an array of an object
[ {hash:"#ghost\n#mik\n#bro"} ]
i want to make the value of hash_tag to have breakline in display in frontend
.
supposedly i display it in frontend and i bind it in a p element
<p v-for="data in dataFromBackend" :key="data.id">{{data.hash}}</p>
this is the script to have breakline in javascript
function nl2br (str, is_xhtml) {
if (typeof str === 'undefined' || str === null) {
return '';
}
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '$2');
};
the function nl2br work if do like this
{{nl2br("mik\nmik\nbro")}}
the output is
mik
mik
bro
but when is try the data from backend its not working
{{nl2br(data.hash)}}
its output plainly
#ghost\n#mik\n#bro