Javascript 如何使用jQueryAjax将包含ReactJs的页面加载到其他页面
我正在处理一个现有的应用程序。我在React Js中写了它的一些观点。现在我想使用jqueryload在其他页面中加载这些视图。那有可能吗Javascript 如何使用jQueryAjax将包含ReactJs的页面加载到其他页面,javascript,jquery,ajax,reactjs,single-page-application,Javascript,Jquery,Ajax,Reactjs,Single Page Application,我正在处理一个现有的应用程序。我在React Js中写了它的一些观点。现在我想使用jqueryload在其他页面中加载这些视图。那有可能吗 [假设leave.html包含react代码。现在我想使用jquery load在index.html中加载leave.html。index.html没有react代码。如何做到这一点]我不确定是否可以将load与react组件一起使用。但是,为什么要使用jquery load,而您可以使用create元素,比如div与id=在index.html中“lea
[假设leave.html包含react代码。现在我想使用jquery load在index.html中加载leave.html。index.html没有react代码。如何做到这一点]我不确定是否可以将load与react组件一起使用。但是,为什么要使用jquery load,而您可以使用create元素,比如
div
与id=在index.html中“leave”
并附加您的react组件让webpack编译器负责将其解析为index.html,leave.html中的代码可以作为jsx文件中的react组件,例如:
import React from 'react';
class Leave extends React.Component {
constructor(props){
super(props);//if you have properties
this.state = {};
this.myFunc= this.myFunc.bind(this); // bind your methods like this.
}
myFunc(){
}
render(){
return (
<div>
<!-- Html content to be added over here. -->
{this.myFunc()}
</div>
);
}
}
export default Leave;
从“React”导入React;
类组件{
建造师(道具){
超级(道具);//如果你有属性
this.state={};
this.myFunc=this.myFunc.bind(this);//像这样绑定您的方法。
}
myFunc(){
}
render(){
返回(
{this.myFunc()}
);
}
}
导出默认休假;
为应用程序创建app.js,并将上述导出模块附加到index.html中
import React from 'react';
import ReactDOM from 'react-dom';
import Leave from './jsx/Leave.jsx'; //import your module from jsx path.
ReactDOM.render(<Leave/>, document.getElementById('leave')); //append the compile data to index.html.
从“React”导入React;
从“react dom”导入react dom;
从“./jsx/Leave.jsx”导入Leave;//从jsx路径导入模块。
ReactDOM.render(,document.getElementById('leave');//将编译数据附加到index.html。
index.html将如下所示:
<html>
<body>
<div id="app"></div>
<script src = "/build/index.js"></script>
<!--index.js is build by webpack-->
</body>
</html>
使用webpack编译react,您将能够在应用程序中使用可重用的组件
谢谢我不确定您是否可以将load与react组件一起使用。但是为什么要使用jquery load,您可以使用create元素,比如
div
与id=“leave”“
在index.html中添加react组件让webpack编译器负责将其解析为index.html,leave.html中的代码可以作为jsx文件中的react组件,例如:
import React from 'react';
class Leave extends React.Component {
constructor(props){
super(props);//if you have properties
this.state = {};
this.myFunc= this.myFunc.bind(this); // bind your methods like this.
}
myFunc(){
}
render(){
return (
<div>
<!-- Html content to be added over here. -->
{this.myFunc()}
</div>
);
}
}
export default Leave;
从“React”导入React;
类组件{
建造师(道具){
超级(道具);//如果你有属性
this.state={};
this.myFunc=this.myFunc.bind(this);//像这样绑定您的方法。
}
myFunc(){
}
render(){
返回(
{this.myFunc()}
);
}
}
导出默认休假;
为应用程序创建app.js,并将上述导出模块附加到index.html中
import React from 'react';
import ReactDOM from 'react-dom';
import Leave from './jsx/Leave.jsx'; //import your module from jsx path.
ReactDOM.render(<Leave/>, document.getElementById('leave')); //append the compile data to index.html.
从“React”导入React;
从“react dom”导入react dom;
从“./jsx/Leave.jsx”导入休假//从jsx路径导入模块。
ReactDOM.render(,document.getElementById('leave'))//将编译数据附加到index.html。
index.html将如下所示:
<html>
<body>
<div id="app"></div>
<script src = "/build/index.js"></script>
<!--index.js is build by webpack-->
</body>
</html>
使用webpack编译react,您将能够在应用程序中使用可重用的组件
谢谢