启用 CSS 隔离 RCL 以在 Blazor 服务器中工作
Enable CSS isolation of RCL to work in blazor server
我有一个 razor class 库和使用该库的 blazor 服务器,RCL 中的每个组件都有自己的 css,在阅读了 Microsoft ASP.NET Core Blazor CSS isolation 的文档后,我做了以下操作:
- 在我的 blazor 服务器的 razor 页面中,我添加了我的组件:
<MyComponent />
- 在 _Host 页面中,我添加了 link 用于捆绑:
<link href="Blazor.Components.styles.css" rel="stylesheet">
。
在 运行 应用程序之后我看不到 MyComponent 的 css。
我是不是做错了什么?你能给我一些建议吗?我读了这个page,它遵循相同的方法,但用于 Webassembly!
谢谢。
引用 Razor class library (RCL) support 文档:
When a Razor class library (RCL) provides isolated styles, the tag's href attribute points to {STATIC WEB ASSET BASE PATH}/{ASSEMBLY NAME}.bundle.scp.css, where the placeholders are:
- {STATIC WEB ASSET BASE PATH}: The static web asset base path.
- {ASSEMBLY NAME}: The class library's assembly name.
In the following example:
- The static web asset base path is _content/ClassLib.
- The class library's assembly name is ClassLib.
<link href="_content/ClassLib/ClassLib.bundle.scp.css" rel="stylesheet">
在 _Host 页面中,您应该添加如下内容:
<link href="_content/YourClassLib/YourClassLib.bundle.scp.css" rel="stylesheet">
我有一个 razor class 库和使用该库的 blazor 服务器,RCL 中的每个组件都有自己的 css,在阅读了 Microsoft ASP.NET Core Blazor CSS isolation 的文档后,我做了以下操作:
- 在我的 blazor 服务器的 razor 页面中,我添加了我的组件:
<MyComponent />
- 在 _Host 页面中,我添加了 link 用于捆绑:
<link href="Blazor.Components.styles.css" rel="stylesheet">
。
在 运行 应用程序之后我看不到 MyComponent 的 css。
我是不是做错了什么?你能给我一些建议吗?我读了这个page,它遵循相同的方法,但用于 Webassembly!
谢谢。
引用 Razor class library (RCL) support 文档:
When a Razor class library (RCL) provides isolated styles, the tag's href attribute points to {STATIC WEB ASSET BASE PATH}/{ASSEMBLY NAME}.bundle.scp.css, where the placeholders are:
- {STATIC WEB ASSET BASE PATH}: The static web asset base path.
- {ASSEMBLY NAME}: The class library's assembly name.
In the following example:
- The static web asset base path is _content/ClassLib.
- The class library's assembly name is ClassLib.
<link href="_content/ClassLib/ClassLib.bundle.scp.css" rel="stylesheet">
在 _Host 页面中,您应该添加如下内容:
<link href="_content/YourClassLib/YourClassLib.bundle.scp.css" rel="stylesheet">