Vue过滤器 filters使用

211 阅读1分钟

使用filters省略10个字符之后的值

el-table-column(label="内容", v-if="formData.list_type == 1", width="200px")
      template(slot-scope="scope")
        span(
          slot="reference",
          style="color: green",
          @click="showcontentdialog(scope.row.content)"
        ) {{ scope.row.content | ellipsis }}
filters: {
    ellipsis(value) {
      if (!value) return "";
      if (value.length > 10) {
        return value.slice(0, 10) + "...";
      }
      return value;
    },
  },

image.png 效果:

image.png