【发布时间】:2022-01-09 17:37:11
【问题描述】:
我已使用 vue 过滤器将文本限制为 100 个字符。我得到的输出为
Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the indu ...
如果看到最后一个字indu ...,。我不想在单词和点的几个字符之间进行单词分解,而是希望它像完整的单词然后是点,如下所示:
Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's ...
单词应在 100 个字符后完成,然后需要附加 ...。
下面是我使用的Vue过滤器,我怎样才能以完整的单词结尾,然后点而不是最后一个单词的几个字符?
msg = "<p> Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing</p>\n"
<h2 v-html="this.$options.filters.limitText(msg)" ></h2>
filters: {
limitText: function (val) {
if(val && (val.length > 100) {
return (val.substr(0, 100) + ' ...')
}
return val;
}
}
【问题讨论】:
标签: javascript vue.js vuejs2