# text-ellipsis-ruby **Repository Path**: rubyLi/text-ellipsis-ruby ## Basic Information - **Project Name**: text-ellipsis-ruby - **Description**: a text-ellipsis plugin - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-09 - **Last Updated**: 2022-10-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # text-ellipsis-ruby 处理单行或多行文本过长时省略号显示 ## Install ``` npm install --save-dev text-ellipsis-ruby ``` ## Usage ```js import { ellipsis } from "text-ellipsis-ruby"; ellipsis.config({ lineNum: 1, // 默认行数 fontFamily: "MicrosoftYahei", // 默认字体 fontWeight: "normal", fontSize: "14px", // 默认字号14px left: "...", tagName: "p", resize: true, }); const ells = document.querySelectorAll(".ell"); ellipsis.init(ells); ``` ```html

``` ## Config You can add config when `ellipsis.config` to set global-config or use the attribute on vue elempent. ## Property | Props | Type | Default | Effect | | ---------- | --------------- | ------------------------------------ | ------------------------------------------------------------------ | | lineNum | Number | 1 (from global config) | The max line. | | fontFamily | String | microsoft yahei (from global config) | The fontFamily to calculate the width. | | fontSize | String\| Number | 14px (from global config) | The fontSize to calculate the width. | | tagName | String | p (from global config) | The tag to show the text. | | left | String | '…' (from global config) | The String add on the end of the last line. | | resize | Boolean | true (from global config) | Add the eventListener resize to window to watch the window change. | ## Methods | Method | Args | Effect | | ------ | ---------------------------------- | -------------------------------------------------------------- | | config | Object: obj | Update the global config. | | init | NodeList: doms \| HTMLElement: dom | Init the ellipsis dom by the config global and attribute both. | | watch | NodeList: doms \| HTMLElement: dom | init the ellipsis dom and watch the change of attribute. | # 2022/10/12 新增:根据字符长度截取显示省略号的 js 工具方法 ## 参数 | 参数名 | 意义 | 类型 | 默认值 | | ------ | ---------------------------- | ------ | ------ | | str | 需要截取的字符串 | Str | - | | lenNum | 指定字符长度(中文算两个字符) | Number | - | --- 下面是一个简单的在 vue2 中使用例子: ```vue ``` 谢谢你的使用~