<template>
<div>
<!-- 文字超出省略指令 v-ellipsis -->
<div class="box" v-ellipsis>
<!-- <div class="box" v-ellipsis="100"> -->
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
</div>
</div>
</template>
<script>
export default {
directives: {
ellipsis: {
inserted(el, binding, vnode) {
console.log(binding);
el.style.width = `${binding.value}px`
el.style.whiteSpace = 'nowrap'
el.style.overflow = 'hidden';
el.style.textOverflow = 'ellipsis';
}
}
}
}
</script>
<style scoped>
.box {
height: 30px;
line-height: 30px;
border: 1px solid #ccc;
}
</style>
|