我安装了一个NugetPacket:ChartJs.Blazor(v1.0(。在_Host.cshtml文件中添加了
<script src="_content/ChartJs.Blazor/moment-with-locales.min.js" type="text/javascript" language="javascript"></script>
<!-- Reference the included ChartJs javascript file. -->
<script src="_content/ChartJs.Blazor/Chart.min.js" type="text/javascript" language="javascript"></script>
<!-- This is the glue between the C# code and the ChartJs charts -->
<script src="_content/ChartJs.Blazor/ChartJsBlazorInterop.js" type="text/javascript" language="javascript"></script>
<!-- Some styling -->
<link rel="stylesheet" href="_content/ChartJs.Blazor/ChartJSBlazor.css" />
当ASPNETCORE_ENVIRONMENT设置为开发时,它可以工作,但当ASPNETCORE_environmental更改为生产应用程序崩溃并返回错误:
Microsoft.JSInterop.JSException: Could not find 'ChartJsInterop' in 'window'.
Error: Could not find 'ChartJsInterop' in 'window'.
为什么在生产模式中有错误,而在开发模式中没有?这个问题有什么解决办法吗?
您确定没有将其添加到<environment>
HTML标记中吗?示例:
<environment exclude="Production">
<script src="_content/ChartJs.Blazor/ChartJsBlazorInterop.js" type="text/javascript" language="javascript"></script>
</environment>
参考:https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/environment-tag-helper?view=aspnetcore-5.0