Sangil's blog

https://github.com/ChoiSangIl Admin

vue replace new line(엔터키, 개행) to br DEV / WEB

2020-09-03 posted by sang12


무슨..... vue에서 엔터키를 개행하는데 삽질을 이렇게 오래할지는 몰랐다..  String으로 변환을 안해주면.. 오류가 날때가 있다... 하하 누군가에겐 도움이 되기를..

methods: {
   handleNewLine(str) {    
       
return String(str).replace(/(?:\r\n|\r|\n)/g,"</br>");
   }
}

사용은 아래와 같이 하면된다!

<p v-html="handleNewLine(text)"></p>

REPLY