react項(xiàng)目中使用新手引導(dǎo)功能

如何在react項(xiàng)目中使用新手引導(dǎo)功能呢?
在網(wǎng)上發(fā)現(xiàn)了幾種插件,都挺不錯(cuò)的,最終還是選擇了 intro.js ,下面介紹一下這個(gè)插件的具體用法
官網(wǎng)地址:https://introjs.com/

npm安裝

npm install intro.js --save

在項(xiàng)目中引入

可以在你的根目錄中引入css樣式

import "intro.js/introjs.css";

在組件中引入intro.js

import IntroJs from "intro.js"

最簡單的用法

 import React from 'react'
 import IntroJs from 'intro.js'
 import { Card, Tooltip, Button } from 'antd';

 class IntroPage extends React.Component {

        startIntro = () => {
            // 獲取包含引導(dǎo)元素的父容器, 并組成IntroJs
            var intro1 = IntroJs(document.getElementById('root'))
            intro1.setOptions({
                prevLabel: "上一步",
                nextLabel: "下一步",
                skipLabel: "跳過",
                doneLabel: "結(jié)束",
            }).oncomplete(function () {
                //點(diǎn)擊跳過按鈕后執(zhí)行的事件
            }).onexit(function () {
                //點(diǎn)擊結(jié)束按鈕后, 執(zhí)行的事件
            }).start();
        }

        // render
        // 關(guān)鍵是data-step 和 data-intro
        render() {
            return (
                <div id='root'>
                    <Card bordered={true} style={{ width: '100%' }} data-step="1" data-intro='開始引導(dǎo)!'>
                        <Button onClick={() => this.startIntro()}>開始引導(dǎo)</Button>
                    </Card>
                </div>
            );
        }
    }

    export default IntroPage

API

IntroJs Props

image

Options Props

image

最后

插件挺好用的,就是格式比較固定,但也能滿足需求,也可以自定義樣式去修改。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容