在Vue2中,可以使用<br>标签来实现换行。在el-table表格数据中需要换行的地方,可以使用字符串拼接的方式,在需要换行的位置插入<br>标签,例如:

data() {
  return {
    tableData: [
      {
        name: 'John',
        age: 18,
        description: '这是一段需要换行的文字<br>第二行文字'
      },
      {
        name: 'Amy',
        age: 22,
        description: '这是一段不需要换行的文字'
      }
    ]
  }
}

在el-table中渲染表格数据时,可以使用自定义列的方式,将description字段中的HTML标签渲染出来即可,例如:

<template>
  <el-table :data="tableData">
    <el-table-column label="姓名" prop="name"></el-table-column>
    <el-table-column label="年龄" prop="age"></el-table-column>
    <el-table-column label="描述">
      <template slot-scope="scope">
        <div v-html="scope.row.description"></div>
      </template>
    </el-table-column>
  </el-table>
</template>

在模板中,我们使用<template>标签定义了一个作用域插槽,并将description字段中的HTML标签渲染到插槽中。这样,我们就可以在el-table表格中实现换行了。

Logo

前往低代码交流专区

更多推荐