vue 文本显示组件

Vue高亮输入 (Vue Highlightable Input)

Highlight and style specific words as you're typing.

键入时突出显示和设置特定单词的样式。

View demo 查看演示 Download Source 下载源

安装 (Install)

npm install vue-highlightable-input --save

用法 (Usage)

在您的模板中添加以下内容: (In your template add this:)

<highlightable-input highlight-style="background-color:yellow" :highlight-enabled="highlightEnabled" :highlight="highlight" v-model="msg"
/>

在您的组件中添加以下内容: (In your component add this:)

import HighlightableInput from "vue-highlightable-input"
export default {name: 'HelloWorld',components : {HighlightableInput},data() {return {msg: '',highlight: [{text:'chicken', style:"background-color:#f37373"},{text:'noodle', style:"background-color:#fca88f"},{text:'soup', style:"background-color:#bbe4cb"},{text:'so', style:"background-color:#fff05e"},"whatever",{start: 2, end: 5, style:"background-color:#f330ff"}],highlightEnabled: true}},
}

道具 (Props)

Name Required Type Default Description Reactive
highlight Yes String or Array null The string or list of words to highlight. This can be a single string value, a RegExp or you can do an array of strings or RegExp or array of Highlight Objects or array of Range Objects. Yes
highlightEnabled No Boolean true If true, will highlight the text Yes
highlightStyle No String background-color:yellow If no style is provided for text, this will act as the global styling for the highlight. Yes
highlightDelay No Number 500 Determines how long in milliseconds to wait before processing the highlights. Setting this to a low value is fine for small text but setting it higher may improve performance significantly for larger text Yes
caseSensitive No Boolean false If true, will treat highlight strings with case sensitivity. Can be overrided per highlight object. Yes
value No String null Raw text value. Yes
fireOn No String keydown The dom event on which the highlight event should be fired. This can be any event that the div content editable can handle. No (only because the listener is being added in mounted)
名称 需要 类型 默认 描述 React性
突出 字符串或数组 空值 要突出显示的字符串或单词列表。 这可以是单个字符串值,RegExp,也可以是字符串数组或RegExp或Highlight Objects数组或Range Objects数组。
highlightEnabled 没有 布尔型 真正 如果为true,则会突出显示文字
HighlightStyle 没有 背景颜色:黄色 如果没有为文本提供样式,则它将用作突出显示的全局样式。
HighlightDelay 没有 500 确定在处理突出显示之前要等待的毫秒数。 将此值设置为较小的值对于较小的文本来说很好,但是将其设置为较高的值可能会明显改善较大的文本的性能
区分大小写 没有 布尔型 如果为true,将以区分大小写的方式对待突出显示的字符串。 可以被每个高亮对象覆盖。
没有 空值 原始文字值。
开火 没有 按键 应当触发亮点事件的dom事件。 这可以是可编辑div内容可以处理的任何事件。 否(仅因为已在安装中添加了侦听器)

高亮对象 (Highlight Object)

{text:'chicken', // Requiredstyle:"background-color:#f37373" // OptionalcaseSensitive: true // Optional defaults to False
}

范围对象 (Range Object)

{start:1, // Requiredend: 9,  // Requiredstyle:"background-color:#f37373" // Optional
}

End must be greater than start. The range end is exlusive in other words ==> start, end)

结束必须大于开始。 范围结束是排他性的,换句话说==>开始,结束)

大事记 (Events)

Name Description
@input Just like a regular input html element you can use this to react to input events
名称 描述
@输入 就像常规的输入html元素一样,您可以使用它来响应输入事件

Note, that you can also you v-model

注意,您也可以v-model

一些注意事项 (Some notes)

  • This is not meant to be used for large scale text highlight because of how inefficient div contentEditable is and also the fact the algorithm I'm using is stupidly inefficient (try entering like a lot of text for highlighting)

    这不适合用于大规模文本突出显示,因为div contentEditable效率很低,而且我使用的算法效率非常低(尝试输入很多文本来突出显示)

  • Good use cases for this are something like what wit.ai does (they probably have a more efficient algorithm though) for highlighting recognized entities on the fly.

    良好的用例类似于wit.ai所做的事情(尽管它们可能具有更有效的算法),以便即时突出显示已识别的实体。

  • Let me know what other use cases you might have!

    让我知道您可能还有其他用例!

翻译自: https://vuejsexamples.com/a-vue-component-to-highlight-text-as-youre-typing/

vue 文本显示组件

vue 文本显示组件_一个Vue组件,可在您键入时突出显示文本相关推荐

  1. vue日期选择组件_一个Vue组件,为波斯开发人员提供日期选择器

    vue日期选择组件 Vue波斯日期选择器 (vue persian datepicker) This is a Jalali date picker component for Vue. 这是Vue的 ...

  2. vue单选框选中_使用vue如何默认选中单选框

    使用了vue以后,发现这真的是一个灵活高效的框架,能够轻松实现页面的实时刷新. 那么,今天先聊聊单选框的使用.一般我们使用单选框,会这么写: //HTML one two three 有"c ...

  3. 动态添加组件_使用vue.js的动态组件模板

    最近刚做完建站工具,准备总结里面使用到的一些技巧,同时会做一版简化的放在 github上. 先来一篇翻译的文章,和我在项目中使用的动态组件思路一样,不过缺少了演化的过程,直接给出了最终的解决方案.这篇 ...

  4. vue 分步引导组件_引导卡组件:完整介绍

    vue 分步引导组件 In this article, I'm going to introduce you to the Bootstrap card component and walk you ...

  5. vue tree组件_使用Vue 3.0做JSX(TSX)风格的组件开发

    前言 我日常工作都是使用React来做开发,但是我对React一直不是很满意,特别是在推出React Hooks以后. 不可否认React Hooks极大地方便了开发者,但是它又有非常多反直觉的地方, ...

  6. vue 添加全局组件_自定义vue全局组件(Loading为例)

    首先创建一个项目 vue init webpack-simple define-demo //define-demo 项目名称 cd define-demo npm install //安装本次所有需 ...

  7. vue 画布插件_一个Vue.js插件,用于使用EaselJS控制HTML5画布

    vue 画布插件 vue-easeljs (vue-easeljs) A Vue.js plugin to control an HTML5 canvas using EaselJS. 一个Vue.j ...

  8. baidumap vue 判断范围_一个Vue引发的性能问题

    笔者最近在一个Vue项目里面引入了一个动画库,但是发现性能有点异常,项目里面使用的CPU是在一个demo页面的3.5倍左右,我已经把项目里所有其它干扰的东西都给删掉了,但是CPU就是降不下去,如下图所 ...

  9. 5e怎么绑定一键跳投_一个 Vue 自定义指令实现一键 Copy的功能

    话不多说先看效果,这个效果是用在真实项目中的实际效果哈: 指令是啥? 按照惯例,先请出官方的解释: 指令 (Directives) 是带有 v- 前缀的特殊特性.指令特性的值预期是单个 JavaScr ...

最新文章

  1. Permission denied: make_sock: could not bind to address [::]:81 Apache 虚拟主机
  2. CoLoRMap: Correcting Long Reads by Mapping short reads CoLoRMap:通过映射短读来纠正长读
  3. C#编程利器系列文章
  4. linux内核内存管理的三个阶段分析
  5. 几步在Eclipse离线安装propedit插件
  6. 2017年,这两个大数据岗位一定会火!
  7. access 报表中序号自动_数据报表多种序号生成方式
  8. 《支付宝的高可用与容灾架构演进》读后感
  9. Android Studio编码问题
  10. ArcGIS水文分析实战教程(10)河流平均比降计算
  11. MySQL学习日志(二)
  12. (5)剑指Offer之栈变队列和栈的压入、弹出序列
  13. 拓端tecdat|如何使用SAS从Excel中读取一系列单元格
  14. android系统关闭wifi,Android以编程方式打开/关闭WiFi HotSpot
  15. Hardware概述
  16. 14-Shiro-单点登录原理
  17. 微信小程序实现倒计时功能(超简单)
  18. 怎么比对两个html列表,两个表格对比,如何快速找出不同数据!
  19. Python名片管理系统
  20. Python图片批量自动抠图去背景

热门文章

  1. 美团2021校招测试
  2. 工欲善其事,必先利其器之-使用Keynote遥控来代替翻页激光笔
  3. 《大问题:简明哲学导论》读书笔记及个人所想
  4. win10怎么进入和退出安全模式?
  5. Facebook Surround360 学习笔记--(3)硬件设计要点
  6. php 强制不换行,HTMLnobr强制不换行标签元素
  7. labelCloud:用于三维点云物体检测的轻量级标注工具
  8. 端口号被占用:Identify and stop the process that‘s listening on port 10000 or configure this application...
  9. android 虚拟键背景,Android 设置应用的底部导航栏(虚拟按键)背景颜色
  10. AnyTXT Searcher