【问题标题】:reactjs: Error in importing uikit.min.jsreactjs:导入uikit.min.js时出错
【发布时间】:2017-06-11 13:20:08
【问题描述】:

我对 react 很陌生,并且不知道如何使用原生 react,所以我使用 create-react-app

我正在尝试使用 UIKit 作为框架,但我无法让它工作。由于 UIKit 的 NPM 模块只支持它的 2.x 版本,我正在尝试使用它的 3.x(来自http://www.getuikit.com/)。我正在我的一个组件中导入 JS 文件 (uikit.min.js),但编译失败。

我在文件中包含import * as uikit from 'uikit.min.js';,编译时会弹出:

./src/assets/js/uikit.min.js
  Line 3:  'define' is not defined         no-undef
  Line 3:  'define' is not defined         no-undef
  Line 4:  Unexpected use of 'location'    no-restricted-globals
  Line 4:  Unexpected use of 'location'    no-restricted-globals
  Line 5:  Unexpected use of 'location'    no-restricted-globals
  Line 5:  'DocumentTouch' is not defined  no-undef
  Line 5:  'MSGesture' is not defined      no-undef

Search for the keywords to learn more about each error.

也许我做错了,但如何导入它以供我使用 UIkit v3?

【问题讨论】:

  • 您可以将它作为脚本依赖项包含在您的 HTML 文件中
  • @ShubhamKhatri 试过了,但我需要使用 UIkit 的功能,例如UIkit.modal("...").toggle()

标签: javascript reactjs create-react-app getuikit


【解决方案1】:

首先使用 npm npm install uikit 安装 UIkit。那么:

import UIkit from 'uikit'

请记住,react 仅适用于数据属性,来自文档的引用:

React 仅适用于 data-uk-* 前缀。

【讨论】:

  • 之前无法做到这一点,因为 uikit 的 npm 模块不是 3.x 而是甜蜜的,3 天前有更新。谢谢你。
  • 很高兴它有帮助。干杯。
猜你喜欢
  • 2020-08-19
  • 2017-03-05
  • 2022-01-18
  • 2019-01-04
  • 2021-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多