A vue component which turns new lines into line breaks.
See Why not just use CSS white-space: pre;
? · Issue #7
- [Vue.js]
^3.0.0-0
npm install --save vue3-nl2br
<nl2br tag="p" :text="`line1\nline2`" class="foo bar" />
is rendered to
<p class="foo bar">line1<br>line2</p>
import Vue from 'vue'
import Nl2br from 'vue3-nl2br'
Vue.component('nl2br', Nl2br)
https://vuejs.org/v2/guide/components.html#Local-Registration
// MyComponent.vue
<template>
<nl2br tag="p" :text="`line1\nline2`" />
</template>
<script>
import Nl2br from 'vue3-nl2br'
export default {
name: 'MyComponent',
components: {
Nl2br,
},
// ...
}
</script>
tag
: HTML tag name which is passed to h function- Type:
String
- Required: true
- Type:
text
: Text in the tag.- Type:
String
- Required: true
- Type:
class
: HTML class name(s)- Type:
String
- Required: false
- Type: