Skip to content

Instantly share code, notes, and snippets.

@bradlis7
Last active September 6, 2017 22:06
Show Gist options
  • Save bradlis7/1883d8658a9ea8548543124cef618692 to your computer and use it in GitHub Desktop.
Save bradlis7/1883d8658a9ea8548543124cef618692 to your computer and use it in GitHub Desktop.
Vue ellipsis component
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
</head>
<body>
<ul id='Vue'>
<li><span is='ellipsis' length='25' text='This should collapse since it has more than 25 characters.'></span></li>
<li><span is='ellipsis' length='50' text='This should remain expanded.'></span></li>
</ul>
<script>
Vue.component("ellipsis", {
props: ["length", "text"],
render: function (createElement) {
var s = this.text;
if (s.length < this.length) {
return createElement("span", s);
}
s = this.text.substr(0, this.length - 2);
var s2 = s.substr(0, s.search(/[\s]+[^\s]*$/));
if (s2.length > 0) s = s2;
return createElement("span", s + "…");
}
});
var x = new Vue({
el: '#Vue',
data: {},
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment