0

Im making error messages with notification in Vue.js.

Tutorial Demo: https://admin.vuebulma.com/#/components/notification

Tutorial Codes: https://github.com/vue-bulma/vue-admin/blob/master/client/views/components/Notification.vue

openNotificationWithType: function (type) {
  openNotification({
    title: 'Error',
    message: 'Hello\nWorld',
    type: type
  })
}

in this code, when i use \n in string, it doesn't render it to linefeed.

So i have been searching how to apply linefeed in JS, but i can't exactly answer.

I tried below:

1)

 message: `Hello
 World`

2)

 message: 'Hello' + 
 '' + 'World'

3)

 message: 'Hello'
 + 'World'

4)

 message: 'Hello' + '\n' + 'World'

5)

 message: 'Hello<br/>World'

6)

 message: 'Hello<br>World'

7)

 message: `Hello \
 World`

8)

 message: [`Hello`,
           `World`].join(' ')

Results:

results of error message

* I'm in Mac OS.

Aaron Ryu
  • 7
  • 6
  • 1 and 4 are equivalent and do what you want, it just doesn't show up because of CSS styling. 2 and 3 produce no space at all, 7 and 8 produce just a blank not a linebreak. – Bergi Oct 31 '17 at 06:53
  • @Bergi I tried 1 and 4, but they don't show what i want. Then how can i change and what do i change in CSS styling for showing what i want? – Aaron Ryu Oct 31 '17 at 07:22

1 Answers1

-1

The browser condenses all whitespace in text content into a single space, and you can't include HTML entities in normal (mustache) interpolation. You need the v-html directive.

<div v-html="rawHtml"></div>

The contents of this div will be replaced with the value of the rawHtml property, interpreted as plain HTML - data bindings are ignored.

So you would have to modify the notification component to use v-html, and then use #5 with it.

tony19
  • 125,647
  • 18
  • 229
  • 307
Roy J
  • 42,522
  • 10
  • 78
  • 102
  • It's not the code in html side, just JS part. But, Thanks for replying – Aaron Ryu Nov 02 '17 at 02:26
  • The JS data for 1 and 4 are exactly what you want. It is the display that is keeping you from seeing it. You cannot display a newline in text content. You need an HTML `
    ` for that, and to insert HTML you have to use `v-html`.
    – Roy J Nov 03 '17 at 12:27