javascript - Css 不适用于 React 中的 intro.js 模块

标签 javascript reactjs intro.js

我在我的组件之一中添加了 Intro.js,如下所示:

import introJs from 'intro.js';

然后在componentDidMount中调用

    componentDidMount() {
    introJs().start();
}

我在其中使用它的元素:

 <div className={cx('dropDownSortingBlock')}>
                {!isTrending && <div className={cx('dropDown')} data-intro={'Hello step one!'}>

但是当我将 css 导入父组件时

enter image description here

它不渲染组件。

enter image description here

更新:

我尝试使用 intro.js react wrapper,现在我已经将 css 直接导入到我的文件中。

然而它就是行不通

 constructor() {
        super();

        this.state = {
            showMessage: false,
            type: '',
            message: '',
            stepsEnabled: true,
            initialStep: 0,
            steps: [
                {
                    element: '.snapshotWrapper',
                    intro: 'Hello step',
                },
                {
                    element: '.snapshotWrapperNew',
                    intro: 'Hello Sort wrapper',
                },
            ],
        };
    }

渲染中

  <Steps
            enabled={this.state.stepsEnabled}
            steps={this.state.steps}
            initialStep={this.state.initialStep}
            onExit={this.onExit}
                    />

下面是显示的内容:

enter image description here

最佳答案

因为您要从 node_modules 中的包中导入 css 文件,所以将 ~ 添加到 ListLandingPage 中的导入中。 CSS :

@import "~intro.js/introjs.css";

参见 Import CSS from "node_modules" in Webpack

或者,将其导入到您的组件中(不带 ~ ):

import introJs from 'intro.js';
import 'intro.js/introjs.css'; 

但是,我建议您使用 React wrapper around Intro.js对于 React 应用。

他们甚至有一个 code sandbox开始

关于javascript - Css 不适用于 React 中的 intro.js 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57373314/

相关文章:

javascript - node.js 中的 UDP 套接字

javascript - 按名称调用或访问本地函数

javascript - 目标容器不是DOM元素。(在react js中使用ant设计的轮播)

reactjs - 有没有办法将 props 隐式传递给组件?

javascript - 如何用另一个 Javascript 更改 Javascript 函数值?

javascript - 错误 : Couldn't find preset "es2015" relative to directory

jquery - 通过元素 ID 或类组启动在 intro.js 中不起作用

javascript - Intro.js 指南编号略有移位

javascript - IntroJS 'refresh' 可以在介绍开始后突出显示元素吗?

javascript - JSON 返回未定义的值