javascript - Vue.js 显示空白(换行符)

标签 javascript vue.js whitespace nl2br

我如何在 vue.js 中显示行距。现在一切都在互相追赶....

已经试过了:

https://laracasts.com/discuss/channels/vue/vuejs-how-to-return-a-string-with-line-break-from-database

但似乎没有任何效果。现在尝试这个 3 天 -_-。

我正在使用 Vue.js 1.0 和 browserify

非常感谢!

--编辑--

<template>
<div>
  <bar :title="title" />
  <div class="Row Center">
    <div class="Message Center" v-if="!loading">
      <div class="Message__body" v-if="messages">
        
        <div class="Message__item__body" v-for="message in messages" v-link="{ name: 'Message', params: { message: message.slug }}">
          <div class="Message__item__body_content">
            <p class="Message__title">{{ message.subject }}</p>
          </div>

          <div class="Message__item__body_content">
            <p>Reacties: {{ message.totalReactions }}</p>
          </div>

          <div class="Message__item__body_content">
            <p>Door: {{ message.user.name }} {{ message.user.last_name }}</p>
          </div>
        </div>

        <pagination :last-page="lastPage" :page="page" :name="Message" />
        <p v-if="noMessages" class="Collection__none">Er zijn momenteel geen berichten voor het topic {{ topic.name }}.</p>
      </div>
    </div>

    <div class="Loader" v-if="loading">
      <grid-loader :loading="loading" :color="color" :size="size" />
    </div>
  </div>

  <div class="Row center" v-if="!loading && page == 1 && topic">
    <div>
      <button type="submit" class="Btn Btn-main" v-link="{ name: 'NewMessage', params: { topic: topic.slug }}">Nieuw bericht</button>
    </div>
  </div>
</div>
</template>

<script>
import Bar              from '../Shared/Bar.vue';
import Pagination       from '../Shared/Pagination.vue';
import Topic            from '../../Services/Topic/TopicService';
import { GridLoader }   from 'vue-spinner/dist/vue-spinner.min.js';

export default {
  components: { Bar, Pagination, GridLoader },    
  data () {
    return {
      title: 'Berichten',
      messages: [],
      topic: null,
      noMessages: false,
      loading: false,
      color: "#002e5b",
      page: 1,
      lastPage: 1,
    }
  },
  route: {
    data ({ to }) {
      this.loading = true;
      this.page = to.query.page || 1;
      Topic.show(this.$route.params.topic, this.page)
           .then((data) => {
             this.topic = data.data.topic;
             if(!data.data.messages.data.length == 0) {
               this.messages = data.data.messages.data;
               this.lastPage = data.data.messages.last_page;
             } else {
               this.noMessages = true;
             }
             this.loading = false;
           });
    }
  }
}
</script>

当我这样做时:

<div class="Message__body__message">
  <p>{{ message.message.split("\n"); }}</p>
</div>

它只添加逗号。

--编辑--

enter image description here

最佳答案

将容器空白样式设置为预行,如:

<div style="white-space: pre-line;">{{textWithLineBreaks}}</div>

关于javascript - Vue.js 显示空白(换行符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40178401/

相关文章:

javascript - 如何在ajax javascript中获取数组(不是json)的值

javascript - 如何修改移动设备和选项卡的引导轮播

javascript - jQuery $.post() 请求除非运行两次否则不起作用

javascript - 浏览器中的事件循环如何同时处理事件队列、作业队列、渲染队列?

css - 卸载/删除动态加载的 css 文件

vue.js - 使用 Echarts 的 vue.js 项目不显示图例

javascript - 在 Vue 中使用组件声明数据

css - YUI 压缩器正在从 calc() 中去除空格

oracle - 停止 SQL*Plus 提示空格

c - 如何允许使用 scanf 输入空格?