1 Star 0 Fork 4

sunzhouhui / vue-ellipsis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vue-ellipsis

基于 Vue2 的自定义文本省略支持。

示例: http://hyjiacan.gitee.io/vue-ellipsis

安装

yarn add @hyjiacan/vue-ellipsis

or

npm install @hyjiacan/vue-ellipsis

用法

import ellipsis from '@hyjiacan/vue-ellipsis'
Vue.use(ellipsis)

import {ellipsisDirective, ellipsisComponent} from '@hyjiacan/vue-ellipsis'
// 注册为指令
Vue.directive(ellipsisDirective.name, ellipsisDirective)
// 注册为组件
Vue.component(ellipsisComponent.name, ellipsisComponent)

// 使用上面的其中一种用法就行了

你需要通过CSS指定宽度

.ellipsis-style{
    width: 200px;
}
.ellipsis-style{
    max-width: 200px;
}

或通过 STYLE

<div style="width: 200px"></div>
<ellipsis style="width: 200px"></ellipsis>

指令

v-ellipsis 的值表示显示的行数,默认值为 1

修饰符

名称 描述
start 使用前置省略模式
middle 使用中置省略模式
end 后置省略模式
always 不论是否被省略,始终显示 title
none 不论是否被省略,始终不显示 title
scale 自动缩放(font-size)文本以适应容器宽度, 此时 不会 省略文本
  • 修饰符 start, middle, end 是互斥的,只能指定其中一个,默认为 end
  • 修饰符 always, none 是互斥的,只能指定其中一个,留空时表示在省略时自动设置 title,相当于组件中的 auto

属性

名称 默认值 描述
data-ellipsis ... 填充文本(代替默认的省略号)
data-delay 200 表示处理的延时(毫秒)

组件

属性

名称 类型 默认值 描述
fill String ... 省略时的默认填充串
position String end 省略位置,可选值: start, middle, end
show-title String - 是否显示 title,可选值: always, none
rows Number 1 显示的行数
scale Boolean false 自动缩放(font-size)文本以适应容器宽度, 此时 不会 省略文本
content String end 设置文本内容,此时会忽略槽 default

插槽

名称 描述
default 内容

常见问题

  1. 问: 为什么容器设置了 padding 为百分比时,显示异常? 答: 暂不支持 padding 为百分比

待办

  • 优化 middle 的显示方式,尽量将填充放在容器中间,而不是两侧按字符数量处理
The MIT License (MIT) Copyright © 2019 hyjiacan. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于 Vue2 的自定义文本省略支持 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/sunzhouhui/vue-ellipsis.git
git@gitee.com:sunzhouhui/vue-ellipsis.git
sunzhouhui
vue-ellipsis
vue-ellipsis
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891