Vue controls the number of words displayed according to the length of the string to exceed the display ellipsis

Use filter in vue 

<span class="icon">{
   
   {item.hashName | ellipsis}}</span>

Define filter 

export default {
  name: 'xx',
  filters: {
    ellipsis (value) {
      if (!value) return ''
      if (value.length > 8) {
        return value.slice(0,8) + '...'
      }
      return value
    }
  }
}

effect:

Guess you like

Origin blog.csdn.net/weixin_44727080/article/details/114012020