Last active
September 6, 2017 22:06
-
-
Save bradlis7/1883d8658a9ea8548543124cef618692 to your computer and use it in GitHub Desktop.
Vue ellipsis component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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