Skip to content

Commit d6272ac

Browse files
author
AiYuZhen
committed
修改参数名字。
优化代码。
1 parent d4098a6 commit d6272ac

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@namespace BootstrapBlazor.Components
22
@inherits BootstrapModuleComponentBase
33
@attribute [BootstrapModuleAutoLoader(JSObjectReference = false, AutoInvokeInit = false, AutoInvokeDispose = false)]
4-
@if (!IsAddToHead)
4+
@if (!AddToHead)
55
{
66
<link @attributes="AdditionalAttributes" href="@GetHref()" rel="@Rel" />
77
}

src/BootstrapBlazor/Components/HtmlTag/Link.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class Link
3434
/// <para>同时在多个组件中使用同一个样式时可以添加到 head 中,减少 DOM 节点。</para>
3535
/// </summary>
3636
[Parameter]
37-
public bool IsAddToHead { get; set; } = false;
37+
public bool AddToHead { get; set; } = false;
3838

3939
[Inject, NotNull]
4040
private IVersionService? VersionService { get; set; }
@@ -48,7 +48,7 @@ public partial class Link
4848
protected override async Task OnAfterRenderAsync(bool firstRender)
4949
{
5050
await base.OnAfterRenderAsync(firstRender);
51-
if (IsAddToHead && firstRender)
51+
if (AddToHead && firstRender)
5252
{
5353
var obj = new { Href = GetHref(), Rel };
5454
await InvokeVoidAsync("init", obj);

src/BootstrapBlazor/Components/HtmlTag/Link.razor.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
export function init(options) {
2-
const href = options.href;
3-
const rel = options.rel;
2+
const { href, rel } = options;
3+
const nhref = new URL(href, document.baseURI);
44
const links = document.head.getElementsByTagName("link");
55
// 遍历所有link元素
66
for (let i = 0; i < links.length; i++) {
77
const hlink = links[i];
8-
var nhref = hlink.baseURI + href;
98
if (hlink.href == nhref && hlink.rel == rel) {
109
return;
1110
}

test/UnitTest/Components/LinkTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Link_IsAddToHead_True()
3737
{
3838
pb.Add(a => a.Href, "http://www.blazor.zone");
3939
pb.Add(a => a.Version, "20220202");
40-
pb.Add(a => a.IsAddToHead, true);
40+
pb.Add(a => a.AddToHead, true);
4141
});
4242
Assert.Equal(string.Empty, cut.Markup);
4343
}

0 commit comments

Comments
 (0)