利用Vue+intro.js實(shí)現(xiàn)頁(yè)面新手引導(dǎo)流程功能
效果圖:
1、安裝 intro.js
npm install intro.js --save
2、在項(xiàng)目的 main.js 中,引入 intro.js 庫(kù)和相關(guān)樣式文件,如下:
// 首頁(yè)引導(dǎo)插件 import intro from 'intro.js' // introjs庫(kù) import 'intro.js/introjs.css' // introjs默認(rèn)css樣式 // introjs還提供了多種主題,可以通過以下方式引入 import 'intro.js/themes/introjs-modern.css' // introjs主題 // 把intro.js加入到vue的prototype中,方便使用,就可以直接通過this.$intro()來調(diào)用了 Vue.prototype.$intro = intro
3、在 data 中配置初始數(shù)據(jù),如下:
data(){ return{ introOption: { // 參數(shù)對(duì)象 prevLabel: '上一步', nextLabel: '下一步', skipLabel: '跳過', doneLabel: '完成', tooltipClass: 'intro-tooltip', /* 引導(dǎo)說明文本框的樣式 */ // highlightClass: 'intro-highlight', /* 說明高亮區(qū)域的樣式 */ exitOnEsc: true, /* 是否使用鍵盤Esc退出 */ exitOnOverlayClick: false, /* 是否允許點(diǎn)擊空白處退出 */ keyboardNavigation: true, /* 是否允許鍵盤來操作 */ showBullets: false, /* 是否使用點(diǎn)顯示進(jìn)度 */ showProgress: false, /* 是否顯示進(jìn)度條 */ scrollToElement: true, /* 是否滑動(dòng)到高亮的區(qū)域 */ overlayOpacity: 0.5, // 遮罩層的透明度 0-1之間 positionPrecedence: ['bottom', 'top', 'right', 'left'], /* 當(dāng)位置選擇自動(dòng)的時(shí)候,位置排列的優(yōu)先級(jí) */ disableInteraction: false, /* 是否禁止與元素的相互關(guān)聯(lián) */ hidePrev: true, /* 是否在第一步隱藏上一步 */ // hideNext: true, /* 是否在最后一步隱藏下一步 */ steps: [], /* steps步驟,可以寫個(gè)工具類保存起來 */ }, tipsImg1: require('./img/tips1.jpg'), // 新手引導(dǎo)的提示圖片 tipsImg2: require('./img/tips2.jpg') // 新手引導(dǎo)的提示圖片 } }
4、在 methods 中配置方法,用以設(shè)置引導(dǎo)步數(shù),如下:
methods: { initGuide() { // 綁定標(biāo)簽元素的選擇器數(shù)組 this.introOption.steps = [ { title: '系統(tǒng)使用指導(dǎo)', element: '#step1', intro: `鼠標(biāo)懸浮在各個(gè)功能模塊上,可快速查找系統(tǒng)對(duì)應(yīng)操作SOP以及運(yùn)維人員。<img src="` + this.tipsImg1 + `" alt="" style="width: 200px;margin-top: 15px;"/>`}, { title: '個(gè)人信息', element: '#step2', intro: `點(diǎn)擊個(gè)人頭像/下拉圖標(biāo),選擇個(gè)人信息,初始密碼為******,建議修改為個(gè)人賬號(hào)密碼。<img src="` + this.tipsImg2 + `" alt="" style="width: 125px;margin-top: 15px;"/>`, }, { title: '重新引導(dǎo)', element: '#step3', intro: '點(diǎn)擊此處可重新查看引導(dǎo)流程。', }, ] this.$intro() .setOptions(this.introOption) // 點(diǎn)擊結(jié)束按鈕后執(zhí)行的事件 .oncomplete(() => { console.log('點(diǎn)擊結(jié)束按鈕后執(zhí)行的事件') }) // 點(diǎn)擊跳過按鈕后執(zhí)行的事件 .onexit(() => { console.log('點(diǎn)擊跳過按鈕后執(zhí)行的事件') }) // 確認(rèn)完畢之后執(zhí)行的事件 .onbeforeexit(() => { console.log('確認(rèn)完畢之后執(zhí)行的事件') }) .start() }, }
5、在 mounted 中調(diào)用方法,如下:
mounted() { this.$nextTick(() => { this.initGuide() // 調(diào)用新手引導(dǎo)的方法 }) }
注意:
(1)上述代碼中,initGuide() 方法里配置了指引步驟和開始指引;并在 mounted 生命周期中調(diào)用 initGuide() 方法以展示指引內(nèi)容。需要注意的是,為確保指引信息在原始頁(yè)面渲染完畢后調(diào)用,需要在 $nextTick()
中調(diào)用 initGuide() 方法。
(2)正常是可以在 mounted 中調(diào)用指引方法,但是如果你的指引塊是通過接口渲染的,那么建議在接口請(qǐng)求成功之后調(diào)用指引方法,避免數(shù)據(jù)為請(qǐng)求成功,指引塊無法正確選中。
6、重新查看新手指引的方法,如下:
// 重新查看引導(dǎo) viewIntro(){ this.initGuide() },
說明:在標(biāo)簽添加點(diǎn)擊事件 viewIntro() ,然后在事件中調(diào)用 this.initGuide() 方法即可。
7、頁(yè)面標(biāo)簽綁定,如下:
<div id="step1"> <div>這里邊是你第一步需要指引所框選的內(nèi)容</div> </div> <div id="step2"> <div>這里邊是你第二步需要指引所框選的內(nèi)容</div> </div> <div id="step3"> <div>這里邊是你第三步需要指引所框選的內(nèi)容</div> </div> <div class="new-tips" @click="viewIntro()">新人教程</div>
注意:標(biāo)簽上的 id 所對(duì)應(yīng)的是 initGuide 方法中 element 的值,每一步都是通過這個(gè) id 進(jìn)行綁定的。
8、css 樣式
<!-- 新手引導(dǎo)提示樣式 --> <style lang="scss"> .introjs-helperLayer{ box-shadow: rgba(33, 33, 33, 0.8) 0px 0px 1px 0px, rgba(33, 33, 33, 0.5) 0px 0px 0px 5000px!important; border: 3px dashed #409eff; } .new-tips{ color: #409eff; line-height: 80px; cursor: pointer; } .introjs-tooltip-title{ font-size: 16px; width: 80%; padding-top: 10px; } .warper { width: 200px; height: 100px; line-height: 100px; text-align: center; border: 1px solid saddlebrown; } /* 重置引導(dǎo)組件樣式(類似element-ui個(gè)人使用) */ .intro-tooltip { color: #ffff; background: #2c3e50; } /* 引導(dǎo)提示框的位置 */ .introjs-bottom-left-aligned { left: 45% !important; } .introjs-right, .introjs-left { top: 30%; } .intro-highlight { background: rgba(255,255,255,0.5); } .introjs-arrow.left { border-right-color: #2c3e50; } .introjs-arrow.top { border-bottom-color: #2c3e50; } .introjs-arrow.right { border-left-color: #2c3e50; } .introjs-arrow.bottom { border-top-color: #2c3e50; } /* 提示框頭部區(qū)域 */ .introjs-tooltip-header { padding-right: 0 !important; padding-top: 0 !important; } .introjs-skipbutton { color: #409eff !important; font-size: 14px !important; font-weight: normal !important; // padding: 8px 10px !important ; } .introjs-tooltipbuttons { border: none !important; } .introjs-tooltiptext { font-size: 14px !important; padding: 15px !important; } /* 提示框按鈕 */ .introjs-tooltipbuttons { display: flex; align-items: center; justify-content: center; } .introjs-button { width: 50px !important; text-align: center; padding: 4px !important; font-size: 12px !important; font-weight: 500 !important; border-radius: 3px !important; border: none !important; } .introjs-button:last-child { margin-left: 10px; } .introjs-prevbutton { color: #606266 !important; background: #fff !important; border: 1px solid #dcdfe6 !important; } .introjs-nextbutton { color: #fff !important; background-color: #409eff !important; border-color: #409eff !important; } .introjs-disabled { color: #9e9e9e !important; border-color: #bdbdbd !important; background-color: #f4f4f4 !important; } </style>
附加:只首次進(jìn)入的時(shí)候顯示引導(dǎo)
新手引導(dǎo)一般只有我們第一次進(jìn)入這個(gè)網(wǎng)站的時(shí)候才會(huì)出現(xiàn)引導(dǎo)內(nèi)容,后續(xù)都不會(huì)再顯示,我們這里如何實(shí)現(xiàn)?
可以通過 localstorge 來存儲(chǔ)一個(gè) key,來判斷用戶是否是第一次進(jìn)入這個(gè)網(wǎng)站,只需要在引導(dǎo)啟動(dòng)時(shí)候加個(gè)判斷就行,代碼如下:
mounted () { this.$nextTick(() => { if (localStorage.getItem('isFirst') === null || localStorage.getItem('isFirst') !== '1') { this.$intro().start() localStorage.setItem('isFirst', 1) } }) },
至此完成,測(cè)試有效?。。?/p>
總結(jié)
到此這篇關(guān)于利用Vue+intro.js實(shí)現(xiàn)頁(yè)面新手引導(dǎo)流程功能的文章就介紹到這了,更多相關(guān)Vue intro.js頁(yè)面新手引導(dǎo)流程內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中el-table前端如何導(dǎo)出excel數(shù)據(jù)表格
這篇文章主要介紹了vue中el-table前端如何導(dǎo)出excel數(shù)據(jù)表格,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07結(jié)合el-upload組件實(shí)現(xiàn)大文件分片上傳功能
Element UI的el-upload上傳組件相信各位小伙伴都已經(jīng)非常熟悉,最近接了一個(gè)新需求,要求在el-upload組件基礎(chǔ)上實(shí)現(xiàn)分片上傳功能,即小于等于5M文件正常上傳,大于5M文件切成5M每片上傳,那么這個(gè)功能怎么實(shí)現(xiàn)呢?一起看看吧2022-09-09Vue中的百度地圖定位BMap.GeolocationControl的用法
BMap.GeolocationControl?是百度地圖API中的一個(gè)類,用于添加地理定位控件到地圖上,以便用戶可以通過該控件獲取自己的當(dāng)前位置,本文給大家介紹Vue中的百度地圖定位BMap.GeolocationControl的用法,感興趣的朋友跟隨小編一起看看吧2023-10-10uni-app中App與webview雙向?qū)崟r(shí)通信詳細(xì)代碼示例
在移動(dòng)應(yīng)用開發(fā)中,uni-app是一個(gè)非常流行的框架,它允許開發(fā)者使用一套代碼庫(kù)構(gòu)建多端應(yīng)用,包括H5、小程序、App等,這篇文章主要給大家介紹了關(guān)于uni-app中App與webview雙向?qū)崟r(shí)通信的相關(guān)資料,需要的朋友可以參考下2024-07-07基于vue-router的matched實(shí)現(xiàn)面包屑功能
本文主要介紹了基于vue-router的matched實(shí)現(xiàn)面包屑功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09餓了么UI中el-tree樹節(jié)點(diǎn)選中高亮的兩種常用方式(highlight-current屬性)
最近新做的項(xiàng)目有用到Element-UI tree組件,下面這篇文章主要給大家介紹了關(guān)于餓了么UI中el-tree樹節(jié)點(diǎn)選中高亮的兩種常用方式(highlight-current屬性),文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12Vue中Router路由兩種模式hash與history詳解
這篇文章主要介紹了Vue中Router路由的兩種模式,分別對(duì)hash模式與history模式作了簡(jiǎn)要分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-09-09Vue + better-scroll 實(shí)現(xiàn)移動(dòng)端字母索引導(dǎo)航功能
better-scroll 是一款重點(diǎn)解決移動(dòng)端(已支持 PC)各種滾動(dòng)場(chǎng)景需求的插件。這篇文章主要介紹了Vue + better-scroll 實(shí)現(xiàn)移動(dòng)端字母索引導(dǎo)航功能,需要的朋友可以參考下2018-05-05vue使用國(guó)密SM4進(jìn)行加密、解密的過程
國(guó)密SM4算法是一種對(duì)稱加密算法,適用于對(duì)稱密鑰加密和解密的場(chǎng)景,這篇文章主要介紹了vue使用國(guó)密SM4進(jìn)行加密、解密,需要的朋友可以參考下2023-07-07