vue-snip

282,875 71
Install
npm install vue-snip
Latest Version:2.0.2
Vue:3
License:MIT
Last Updated:May 9, 2026
Links: GitHub  ·  npm
Maintainer: ajobi

vue-snip

GitHub js-standard-style npm bundle size

Vue.js directive that clamps the content of a text element if it exceeds the specified number of lines.

Key features:
  • two snipping approaches (CSS / JavaScript) picked on a per-element basis
  • no need to specify line heights
  • re-snipping on element resize and reactive data change

To get a hands-on experience try the Interactive Demo.

Installation

# install with npm
npm install vue-snip

# or with yarn
yarn add vue-snip

Vue 2

import Vue from 'vue'
import VueSnip from 'vue-snip'
import App from './App'

Vue.use(VueSnip)

new Vue({ render: h => h(App) }).$mount('#app')

Vue 3

import { createApp } from 'vue'
import VueSnip from 'vue-snip'
import App from './App'

createApp(App).use(VueSnip).mount('#app')

Usage

<!-- minimal example -->
<template>
  <p v-snip> ... </p>
</template>
<!-- with options -->
<template>
  <p v-snip="{ lines: 3 }"> ... </p>
</template>
<!-- with several options -->
<template>
  <p v-snip="{ lines: 3, mode: 'js', midWord: false }"> ... </p>
</template>
<!-- with options and callback -->
<template>
  <p v-snip="{ lines: 3, onSnipped }"> ... </p>
</template>

<script>
export default {
  data () {
    return {
      hasEllipsis: false,
    }
  },
  methods: {
    onSnipped (newState) {
      this.hasEllipsis = newState.hasEllipsis
    }
  }
}
</script>

How it works

The library uses js-snip under the hood. You can find more about the options and how snipping works in its documentation.

Change Log

All changes are documented in the change log.

Related Packages

@boyuai/vue-clamp

Clamping multiline contents with ease.

1,449 8
@clampy-js/vue-clampy

Vue.js (2+) directive that clamps the content of an element by adding an ellipsi...

22,501 75
vue-ellipsis

a substr component of vue2.js

10,053 24
vue-ellipsis-3

一个高性能、可自定义的 vue3 文本缩略组件。

48,433 15
vue-clamp

Clamping primitives for Vue.

831,413 842

Version History

Version Released License
2.0.2 MIT
2.0.1 MIT
2.0.0 MIT
1.3.0 MIT
1.2.0 MIT
Pre-releases (18)
Version Released License
1.0.0-beta.11 MIT
1.0.0-beta.10 MIT
1.0.0-beta.9 MIT
1.0.0-beta.8 MIT
1.0.0-beta.7 MIT