【问题标题】:CSS from Blazor Component Lib not loaded未加载 Blazor 组件库中的 CSS
【发布时间】:2020-01-06 08:45:07
【问题描述】:

我想在我的 BlazorControllers/Components/. 文件中使用位于 wwwroot/css/. 上的自定义 CSS,但在执行时没有加载任何内容。 在客户端或 lib 项目设置中有什么要指定的吗?

我的库项目是BlazorControllers,我在客户端项目中使用库的组件

【问题讨论】:

  • 1.您是否在主页中添加了<link rel="stylesheet" href="~/css/MyComponents.css" />(例如_Host.cshtml)? 2. BlazorControllers 项目是 Razor 类库吗?
  • @itminus 使用~/css/MyComponents.css 不起作用,但使用_content/BlazorControllers/css/MyComponents.css 路径运行良好。我不知道两者有什么区别。
  • _content 是一个伪文件夹,配置为从某处获取文件(通过 StaticFiles 中间件)。与 _framework 比较 Index.html 底部的主 js 文件。

标签: asp.net-core razor blazor


【解决方案1】:

在您的 Index.html(或 _Host.cshtml)文件中,在 site.css 行下方,添加

<link href="_content/<YourLibrary>/styles.css" rel="stylesheet" />

在您的情况下,&lt;YourLibrary&gt; 似乎是 BlazorControllers。

当我正确地阅读那张照片时,你(也)需要

<link href="_content/BlazorControllers/css/MyComponents.css" rel="stylesheet" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-01
    • 2020-05-11
    • 2021-04-07
    • 2023-03-16
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    相关资源
    最近更新 更多