我目前在我的应用程序中有1个反应组件渲染,但是我无法在应用程序中注入任何其他组件。当我将第二个组件注入html文件时,我在控制台中没有收到任何错误。在这一点上,我不确定我还缺少什么呢?欢迎任何和所有建议! (注意:我在BundleConfig.cs文件中包含了一个反应引用)
这是我调用组件的.cshtml文件:
@model List<object>
@using ms.jts.courtspace.web001Web.Models
@{
ViewBag.Title = "Administration";
}
<h2>Administration</h2>
<div id="admin"
data-userType="@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));">
</div>
@section Scripts{
<script src="@Url.Content("~/Scripts/moment.min.js")"></script>
@Scripts.Render("~/bundles/react")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/spcontext")
<script type="text/jsx" src="@Url.Content("../../App/admin.js")"></script>
}
这是我的反应组件,我也使用primereact。
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { TabView, TabPanel } from 'primereact/components/tabview/TabView';
class TabViewDemo extends React.Component {
render() {
return (
<TabView>
<TabPanel header="Godfather I" leftIcon="fa-calendar">
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughters wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his fathers business.
Through Michaels life the nature of the family business becomes clear. The business of the family is just like the head
of the family, kind and benevolent to those who give respect,
but given to ruthless violence whenever anything stands against the good of the family.
</TabPanel>
<TabPanel header="Godfather II" rightIcon="fa-print">
Francis Ford Coppolas legendary continuation and sequel to his landmark 1972 film, The_Godfather parallels the young
Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfathers depiction of the dark side of
the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family.
Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, killing the local Black Hand
Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows.
</TabPanel>
<TabPanel header="Godfather III" leftIcon="fa-bell-o" rightIcon="fa-bookmark-o">
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this
third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone,
now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
</TabPanel>
</TabView>
)
}
}
ReactDOM.render(<TabViewDemo />, document.getElementById("admin"));
{
"version": "1.0.0",
"name": "jts.court.space",
"private": true,
"devDependencies": {
"webpack": "3.10.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "6.24.1",
"babel-loader": "7.1.2",
"babel-core": "^6.26.0"
},
"dependencies": {
"axios": "0.17.1",
"primereact": "^1.3.0",
"pusher-js": "4.2.1",
"react": "16.2.0",
"react-dom": "16.2.0",
"react-router-dom": "^4.2.2",
"react-addons-css-transition-group": "^15.6.2",
"font-awesome": "^4.7.0",
"classnames": "^2.2.5",
"react-burger-menu": "^2.1.11"
},
"scripts": {
"build": "webpack --config webpack.config.js"
},
"-vs-binding": {
"AfterBuild": [
"build"
]
}
}
"use strict";
module.exports = {
entry: {
app: "./App/app.js",
admin: "./App/admin.js"},
output: {
filename: "./Scripts/bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
presets: ["env", "react"]
}
},
]
}
};
答案 0 :(得分:1)
我的解决方案的答案是基本上在我的webpack.config.js文件中创建另一个入口点。然后在输出中我必须修改文件名以生成两个单独的bundle.js文件。这就是我更新的wepback.config.js文件现在的样子:
"use strict";
module.exports = {
entry: {
app: "./App/app.js",
admin: "./App/admin.js"
},
output: {
filename: "./Scripts/[name]-bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
presets: ["env", "react"]
}
},
]
}
};
最后,我必须在BundleConfig.cs中添加这两个新的bundle.js文件,如下所示:
bundles.Add(new ScriptBundle("~/bundles/react").Include(
"~/Scripts/app-bundle.js",
"~/Scripts/admin-bundle.js"));
我是React的新手,但希望这可以帮助别人。