【问题标题】:How to render line-break ↵ in VueJS?如何在 VueJS 中渲染换行符↵?
【发布时间】:2021-06-29 18:02:32
【问题描述】:

我想在 Vue 中有 ↵ 时渲染一个换行符。

我关注了How can I use v-html on the vue?,但我无法关注。

我尝试过的:

var app = new Vue({
  el: '#app',
  data() {
    return {
      a: {
        country: "England:↵ - Liverpool↵ - Chelsea↵ - Arsenal↵ - MU↵ - City",
      },
      testObj: "",
    };
  },
  computed: {
    jsonFunc() {
      return (this.testObj = this.a.country.replace(/↵/g, "<br/>"));
    },
  },
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div>
    Vue
    {{ jsonFunc }}
  </div>
</div>

【问题讨论】:

  • &lt;div v-html="jsonFunc"&gt;&lt;/div&gt; codesandbox

标签: javascript vue.js


【解决方案1】:

使用v-html 指令

<template>
  <div >
    Vue
    <span v-html='jsonFunc'></span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      a: {
        country: "England:↵ - Liverpool↵ - Chelsea↵ - Arsenal↵ - MU↵ - City",
      },
      testObj: "",
    };
  },

  computed: {
    jsonFunc() {
      return (this.testObj = this.a.country.replace(/↵/g, "<br/>"));
    },
  },
};
</script>

【讨论】:

    猜你喜欢
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2017-07-01
    • 1970-01-01
    相关资源
    最近更新 更多