VueJS newline character is not rendered correctly

前端 未结 3 1480
心在旅途
心在旅途 2021-02-19 00:39

I got the following problem, I read data string from an API which contains new line characters \\n and I want to display them correctly in my template.

But

3条回答
  •  终归单人心
    2021-02-19 00:50

    Use the

     tag to preserve the preformated text. More info MDN Pre tag docs

    new Vue({
      el: '#app',
      data: {
        text: 'Hello, \n what\'s up? \n My name is Joe'
      }
    })
    
    
    
    {{ text }}

提交回复
热议问题