当前位置: 首页 > news >正文

动态型网站建设网站外链平台

动态型网站建设,网站外链平台,江门网站免费制作,带漂浮广告的网站实现弹窗展示富文本数据#xff0c;允许全文搜索高亮显示搜索内容 #x1f449; 前言#x1f449; 一、效果演示#x1f449; 二、实现思路#x1f449; 三、实现案例#x1f44d; 卷王必胜#xff01;往期内容 #x1f4a8; #x1f449; 前言 在 Vue elementUi 开… 实现弹窗展示富文本数据允许全文搜索高亮显示搜索内容 前言 一、效果演示 二、实现思路 三、实现案例 卷王必胜往期内容 前言 在 Vue elementUi 开发中遇到需要实现一个富文本展示 且 需要实现富文本全文搜索高亮对应搜索内容。显示关键词出现次数允许上下按顺序切换实现滚动条定位到对应关键词位置 接下来简单阐述下开发中使用方法 一、效果演示 话不多说先上效果图 白嫖万岁当然如果有帮助希望不要吝啬你的点赞呀 以上数据来源于互联网记载的国内法律法规条例文献 二、实现思路 通过 v-html 将富文本解析到页面指定位置展示并且预设的 class名称通过 document.querySelectorAll() 查询已渲染到页面的内容。 通过正则 htmlContent.replace(new RegExp(this.keyword, g), 替换内容。替换内容通常为html样式的keyword) 其实不难发现在vue和 JavaScript 中进行全文搜索有些许不同。由于其中搜索的HTML是我们通过 v-html渲染 到页面上它享有Vue数据双向绑定的特性我们其实只需要对v-html绑定的变量参数进行修改即可实时渲染到页面。当然有些标签属性变更使用JavaScript来修改可能会更加高效一点。 稍微增加一点切换的滚动条挪动 及 样式清除细节逻辑直接看代码吧 简单易懂 三、实现案例 父组件中引用 template fullTextSearchDialogv-iflawDialogVisiblereffullTextSearchDialog:curTitlecurTitle:contentlawFullTextclosecloseLawFullTextDialog / /templatescript import fullTextSearchDialog from /views/components/dialog/fullTextSearchDialog.vue;data() {return {lawDialogVisible: false,curTitle: ,lawFullText: ,} } methods: {// 打开法律法规全文openLawFullTextDialog(item) {this.curTitle item.title;this.lawFullText item.fullText;this.lawDialogVisible truesetTimeout(() {this.$refs.fullTextSearchDialog.openDialog()}, 0)},// 关闭全文弹窗closeLawFullTextDialog() {this.curTitle ;this.lawFullText this.lawDialogVisible false}, } /script子组件模板 templateel-dialog:titlecurTitle -全文:visible.synclawDialogVisiblewidth61.7%height500:close-on-click-modaltrue:modalfalsecustom-classabolishDialogclosehandleClosediv classlawContentdiv classsearchBox全文内容搜索el-inputplaceholder请输入关键词v-modelkeywordclassinput-with-select:clearablefalsestylewidth: calc(100% - 240px);div classindexChange slotsuffixspan classindex{{ searchIndex / searchAllIndexs }}/spandiv classbtnBoxi classel-icon-arrow-up clicksearchIndexDown/ii classel-icon-arrow-down clicksearchIndexUp/i/div/div/el-inputel-button typeprimary sizemini clicklawFullTextSearch查 询/el-buttonel-button sizemini clickresetSearch(true)重 置/el-button/divdiv classfullTextContentpv-ifrefreshstylewidth: 100%;v-htmllawFullText || 暂无数据classel-tiptap-editor__content/p/div/div/el-dialog /templatescript export default {components: {},props: {curTitle: {type: String,default: () {return 提示;},},content: {type: String,default: () {return ;},},},data() {return {lawDialogVisible: false, //弹框显隐lawFullText: ,searchIndex: 0,searchAllIndexs: 0,keyword: ,refresh: true,};},mounted() {this.lawFullText JSON.parse(JSON.stringify(this.content))},watch: {},computed: {},methods: {/*** description:打开弹框回调*/openDialog() {this.lawDialogVisible true;},// 法律法规全文内容关键词搜索高亮lawFullTextSearch() {// window.console.log(this.keyword)if (this.keyword this.keyword ! this.lawFullText.indexOf(this.keyword) ! -1) {this.searchAllIndexs (this.lawFullText.split(this.keyword).length - 1) || 0this.searchIndex 1this.lawFullText this.lawFullText.replace(new RegExp(this.keyword, g), em classsearchText${this.keyword}/em); // 通过正则全局匹配关键字查出来的文字进行高亮替换setTimeout(() {let allSearchIndex document.querySelectorAll(em)allSearchIndex[this.searchIndex - 1].className curSearchText// 使滚动条滚动到指定位置this.scrollChange()}, 0)} else {this.resetSearch()this.$message.info(无当前查询内容 或 未输入关键词)}},// 重置搜索内容resetSearch(resetKey false) {if(resetKey) {this.keyword }this.searchAllIndexs 0;this.searchIndex 0;// 清除上次的查询记录this.lawFullText this.lawFullText.replace(new RegExp(/?em.*?, gi), );// 刷新this.refresh false;setTimeout(() {this.refresh true;}, 0)},// 查询内容上一个searchIndexUp() {if(this.searchIndex 0 this.searchIndex this.searchAllIndexs this.searchAllIndexs 0) {this.searchIndex (this.searchIndex 1) this.searchAllIndexs ? 1 : (this.searchIndex 1)setTimeout(() {let allSearchIndex document.querySelectorAll(em)// 清除上一个选中样式allSearchIndex[this.searchIndex - 2 0 ? this.searchAllIndexs - this.searchIndex : this.searchIndex - 2].className searchTextallSearchIndex[this.searchIndex - 1].className curSearchText// 使滚动条滚动到指定位置this.scrollChange()}, 0)} else {this.searchIndex 0}},// 查询内容下一个searchIndexDown() {if(this.searchIndex 0 this.searchIndex this.searchAllIndexs this.searchAllIndexs 0) {this.searchIndex (this.searchIndex - 1) 0 ? this.searchAllIndexs : (this.searchIndex - 1)setTimeout(() {let allSearchIndex document.querySelectorAll(em)// 清除上一个选中样式allSearchIndex[this.searchIndex this.searchAllIndexs - 1 ? this.searchAllIndexs - this.searchIndex : this.searchIndex].className searchTextallSearchIndex[this.searchIndex - 1].className curSearchText// 使滚动条滚动到指定位置this.scrollChange()}, 0)} else {this.searchIndex 0}},/*** description:关闭弹框回调*/handleClose() {this.lawDialogVisible false;setTimeout(() {this.lawFullText this.keyword this.searchIndex 0this.searchAllIndexs 0this.$emit(close)}, 0)},// 滚动条定位scrollChange() {let fullTextDom document.querySelector(.fullTextContent)let curDom document.querySelector(.curSearchText).parentNode// window.console.log(curDom, curDom.offsetTop)fullTextDom.scrollTop curDom.offsetTop - 137 || 0},}, }; /scriptstyle langscss scoped /deep/ {.abolishDialog {background: #ffffff !important;border: 1px solid #cccccc !important;box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);border-radius: 4px;position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);margin-top: 0 !important;min-width: 480px;.lawContent {height: 50vh;min-height: 500px;display: flex;align-content: space-around;flex-wrap: wrap;.searchBox {width: 100%;display: flex;justify-content: space-around;align-items: center;.el-input__inner {padding-right: 100px;}.el-input__suffix-inner {width: 90px;display: flex;justify-content: space-between;.indexChange {width: 100%;display: flex;justify-content: space-around;align-items: center;.btnBox {display: flex;flex-direction: column;margin: 0 5px;}}}}.fullTextContent {width: 100%;height: calc(100% - 70px);padding-top: 20px;overflow-y: auto;.searchText {background-color: yellow;color: #333;font-weight: bold;margin: 0 3px;padding: 2px;border-radius: 5px;}.curSearchText {background-color: red;color:white;padding: 3px;font-weight: bold;margin: 0 3px;padding: 2px;border-radius: 5px;}}}.el-dialog__header {border-bottom: 0.5px solid #cccccc !important;padding: 0 15px;font-weight: bold;display: flex;align-items: center;justify-content: space-between;.el-dialog__headerbtn {width: 20px;position: relative;top: 0;right: 0;}// height: 48px !important;}.el-dialog__body {// min-height: 100px;padding: 15px;.title {font-size: 10.5px;color: #f56c6c;text-align: right;margin-top: 15px;}}.el-dialog__footer {border-top: 0.5px solid #cccccc !important;padding: 10px;}} } /style案例较为粗浅仅供参考 卷王必胜 如果本篇文章对您有所帮助 请不要吝惜您的小手给小温来个小小的点赞您的支持是对小温无比的认同 往期内容 每日算法一文带你认识 “ 双指针算法 ” 每日小技巧 基于Vue状态的过渡动画 - Transition 和 TransitionGroup JavaScript技术分享 大文件切片上传 及 断点续传思路 每日份知识快餐axios是什么如何在Vue中 封装 axios 面试知识点什么是 Node.js 有哪些优缺点应用场景
http://www.dnsts.com.cn/news/77583.html

相关文章:

  • 学院网站建设分工定制商品的网站建设
  • 说做网站被收债怎么把园林设计网站做的酷炫
  • 高端网站设计推广v信haotg8百度网站的总结
  • 国外优秀的网站建设公司室内设计说明200字
  • 做外国网站百度搜到wordpress虚拟主机安装教程
  • 可以进入任何网站的浏览器wordpress twig
  • 适合个人做外贸的网站企业网站建设要求
  • 三只松鼠建设网站前的市场分析网站联系qq代码
  • 大港天津网站建设比较好的网站空间
  • seo网站营销推广全程实例pdf灵台门户网站建设
  • 法律对网站建设的规制wordpress全景图
  • 美容平台网站建设网站开发培训哪里好
  • 单位网站平台建设汇报新手学做网站下载
  • 注册了域名之后如何建立一个网站拼团购物网站怎么做
  • 营销型网站建设+课程行业协会网站建设的方案
  • 朔州做网站创意极简logo
  • 婚纱网站怎么做seo生鲜网站制作
  • 网站开发公司哪家最强郴州网站制作
  • 河北邢台做网站设计平面图
  • 姑苏网站建设网站如何做原创
  • 163网站建设百度一下你就知道官网下载安装
  • 网站制作 技术农八师建设兵团社保网站
  • 黄页营销网站视频免费大全静态网页设计源代码
  • 虚拟主机怎么设计网站吗网站被别人做镜像
  • 做网站的语言遂昌网站建设
  • 浏览有关小城镇建设的网站南京app开发定制
  • 武进区建设局网站佛山网站建设及优化公司
  • 宁波自助建站网站网络推广平台公司
  • 河南住房和城乡建设厅职称网站html设计网页作业
  • 定制专业网站个人网站源代码