我一生都无法弄清楚将类成员绑定到属性的正确语法是什么。特别是在这种情况下,标签或 Blazor 标签的 href 属性。
我想做的是这个,与 Vue.js 等效的例子
<a :href="'/customers/' + customer.CustomerID">
Run Code Online (Sandbox Code Playgroud)
如何在 Blazor 组件中执行此操作?
我试过了:
<a @bind-href="/customers/customer.CustomerID">
<a @bind-href="/customers/@customer.CustomerID">
<a href="/customers/customer.CustomerID">
<a href="/customers/@customer.CustomerID">
Run Code Online (Sandbox Code Playgroud)
什么都行不通。CustomerID 是 int 类型。
我已经看到了如何使用该@ref属性从父组件调用子组件方法的示例,但是当我尝试将其与foreach循环一起使用时,只有最后渲染的组件的方法被调用,而不是全部。以下是我的组件的示例。
父组件:
<button type="button" class="btn btn-link" @onclick="BtnSyncAll_Click">Run<button>
@foreach(var site in Sites)
{
<Site @ref="SiteView" @Code="@site"></Site>
}
@code {
protected Site SiteView;
protected List<string> Sites { get; set; } = new List<string>
{
"A00001",
"A00002"
};
protected async Task BtnSyncAll_Click()
{
await SiteView.Sync();
}
}
Run Code Online (Sandbox Code Playgroud)
子组件(Site.razor):
<div>
<p>@Code>/p>
</div>
@code {
[Parameter]
public string Code { get; set; }
protected async Task Sync()
{
await ...
}
}
Run Code Online (Sandbox Code Playgroud) 在 Mozilla Firefox 中收到此警告:
Cookie “portalroles” will be soon rejected because it has the “sameSite” attribute set to “none” or an invalid value, without the “secure” attribute. To know more about the “sameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite
Run Code Online (Sandbox Code Playgroud)
有谁知道“很快”大约是什么时候,如果被拒绝,我假设 Firefox 将不允许创建此类 cookie?
编辑:我没有提到我检查了警告链接到的文章,但我找不到任何表明时间范围或拒绝意味着什么的内容。
我读过的所有内容都指向我使用 NavigationManager.LocationChanged 事件,但是它不会检测仅查询字符串何时更改。因此,没有任何东西着火。
我已经尝试过这里建议的内容,但这并不符合我的要求。
每次当前路由中的查询参数发生变化时,我都需要我的组件重新渲染。有人能够做到这一点吗?
更新:
这是我的代码示例:
@page "/accounts"
@if (Accounts != null)
{
<table>
<tbody>
@foreach (var account in Accounts)
{
<tr>
<td>
<NavLink href="/accounts/?accountId={account.AccountId}">@Account.Name</NavLink>
</td>
</tr>
}
</tbody>
</table>
}
@if (Account != null)
{
<div>
<h2>@Account.Name</h2>
</div>
}
@implements IDisposable
@inject NavigationManger NavManager
@inject AccountService AccountService
@code {
protected Guid Id { get; set; } = Guid.NewGid();
protected Guid AccountId { get; set; } = Guid.Empty;
protected List<AccountModel> Accounts { get; set; }
protected AccountModel Account …Run Code Online (Sandbox Code Playgroud) 拉拉维尔 5.8
我对整个推送功能很陌生,我一直在遵循本教程并尝试它,
使用 Laravel 和 Pusher Channels 创建 Web 通知。
我已经一步一步地进行了操作,当我到达通过访问测试网址手动测试事件的步骤时,我收到以下异常:
照亮\广播\广播异常 无消息
C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php
这是代码:
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException( // <-- Exception at this line
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
/**
* Get the Pusher SDK instance.
*
* @return \Pusher\Pusher
*/
public function getPusher()
{
return …Run Code Online (Sandbox Code Playgroud)