如何导入才能在javascript中工作?

时间:2019-01-08 07:25:00

标签: javascript reactjs accordion

我正在尝试使用本教程https://github.com/springload/react-accessible-accordion

向我的网站添加手风琴

我按照他们的说明安装了软件包。然后,我将他们的代码放入名为Accordion.js的文件中,并使用src将其放入html。

这是Accordion.js中的代码,但是我得到了导入行的错误意外标识符。知道出了什么问题吗?

import React from 'react';
import ReactDOM from 'react-dom';

import {
    Accordion,
    AccordionItem,
    AccordionItemTitle,
    AccordionItemBody,
} from 'react-accessible-accordion';

// Demo styles, see 'Styles' section below for some notes on use.
import 'react-accessible-accordion/dist/fancy-example.css';

const Example = () => (
    <Accordion>
        <AccordionItem>
            <AccordionItemTitle>
                <h3>Simple title</h3>
            </AccordionItemTitle>
            <AccordionItemBody>
                <p>Body content</p>
            </AccordionItemBody>
        </AccordionItem>
        <AccordionItem>
            <AccordionItemTitle>
                <h3>Complex title</h3>
                <div>With a bit of description</div>
            </AccordionItemTitle>
            <AccordionItemBody>
                <p>Body content</p>
            </AccordionItemBody>
        </AccordionItem>
    </Accordion>
);

ReactDOM.render(<Example />, document.querySelector('[data-mount]'));

1 个答案:

答案 0 :(得分:-1)

  

有什么想法吗?

您使用src输入HTML。

该模块被标记为React组件,您应该将import插入React应用程序中而不是常规的HTML文档中。