How to make string truncate filter in Vue.js

「文字数省略」の画像検索結果

In this case, like truncate filter.

write in <script>

export default { 
filters: {
    truncate: function(value) {
      var length = 20;
      var ommision = "...";
      if (value.length <= length) {
        return value;
      }
      return value.substring(0, length) + ommision;
    }
  },
}

and, use this like.

<p>{{msg | truncate}}</p>

Leave a Comment

Your email address will not be published. Required fields are marked *