【发布时间】:2019-09-25 16:33:02
【问题描述】:
我正在使用已编译的库在我的 Drupal 上创建一个 React 应用程序。
https://unpkg.com/react@16/umd/react.production.min.js: { external: true, minified: true }
https://unpkg.com/react-dom@16/umd/react-dom.production.min.js: { external: true, minified: true }
https://unpkg.com/babel-standalone@6.15.0/babel.min.js: { external: true, minified: true }
在自定义代码中,我定义了一个文件 (app.js),我可以看到 react 应用程序运行良好。
示例代码:
class App extends React.Component {
// Define default values.
constructor(props) {
super(props);
// Setting up initial state
this.state = {
data: []
}
}
// Call the componentDidMount().
componentDidMount() {
// Here I build a code to create a value to render.
}
render() {
// Here I call the element to render...
})
return (
.....
但是,如果我想调用外部组件,我会遇到问题。如果我在 app.js 的开头添加导入,我会收到错误:
// import { mycomponent } from './mycomponent.js';
// import mycomponent from './mycomponent';
// const { mycomponent } from './mycomponent';
// ....
error: .... require not defined
为了调用我的组件,我尝试使用 import 或 const 但没有成功。
我不在这个项目上使用 node.js(或 browserify...),只使用上面编译的库。在阅读了很多帖子之后,我看不到如何导入/调用我的组件。
我可以在没有这些默认 React 元素的情况下调用外部组件吗:node.js...?
感谢您的帮助。
【问题讨论】:
标签: javascript reactjs react-native drupal