Home > Mobile >  Is there a way to use newline characters in vue.js
Is there a way to use newline characters in vue.js

Time:11-02

I would like to use a newline character (\n) in a string in vue.js

For example:

created() {
    this.buttons = [
      {
        id: 1,
        text: "Button \n 1",
      },
      {
        id: 2,
        text: "Button \n 2",
      },
      {
        id: 3,
        text: "Button \n 3",
      },

Is there another way to do this, because that does not work? I don't want to use <pre, white-space: pre or white-space: pre-wrap.

Thank you in advance

CodePudding user response:

Yes. You can use <br> (HTML code) instead of \n.

And in the HTML use it this way:

<div v-html="text">

[Edit]

Please see the following fiddle.

CodePudding user response:

try this:

text: "Button\ 3"

ust enter a back-slash and keep on - hopefully this works now!

  • Related