[英]How to import dependencies in reactjs class?
I created a react jsx file (index.jsx) as shown below. 我创建了一个反应jsx文件(index.jsx),如下所示。 The first line is used to import jquery library in our class.
第一行用于在我们的类中导入jquery库。
import $ from 'jquery'
import React from 'react';
import ReactDOM from 'react-dom';
import './main.css';
import './component';
import Search from './search/search'
when I started the webpack-dev-server, I got below error: 当我启动webpack-dev-server时,出现以下错误:
index.jsx Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import $ from 'jquery';
| import React from 'react';
| import ReactDOM from 'react-dom'
I have added the jquery and react dependencies on my package.json file. 我已经添加了jquery并对我的package.json文件进行了依赖。 I wonder what I missed here.
我想知道我在这里错过了什么。
The question is tagged as React, but I don't see it. 这个问题被标记为React,但我看不到。 If you want to use React, do something like:
如果要使用React,请执行以下操作:
HelloWorld.js: HelloWorld.js:
import React from 'react';
import ReactDOM from 'react-dom';
import $ from 'jquery';
var HelloWorld = React.createClass({
render: function(){
return <h1> Hello World! </h1>
}
});
ReactDOM.render(<HelloWorld />, document.getElementById('content'));
index.html: index.html:
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
<div id='content'/>
</body>
</html>
If you don't want to use React, please post your other code so we can see how everything couples together, and where things go wrong. 如果您不想使用React,请发布您的其他代码,以便我们了解一切如何结合在一起,以及哪里出了问题。
juste do : 只是做:
var $ = require("query");
module.exports = {
function(){
var element = document.createElement('h1');
element.innerHTML = 'Hello world';
return element;
}
}
another syntaxe can be : 另一个语法可以是:
var $ = require("query");
module.exports = {
myFunction : function(){
var element = document.createElement('h1');
element.innerHTML = 'Hello world';
return element;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.