【发布时间】:2020-07-20 14:45:30
【问题描述】:
用户界面部分
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect">AppId</label>
</div>
<select class="custom-select" id="inputGroupSelect" @bind="@appId">
@if (appIds != null)
{
foreach (var appId in appIds)
{
<option value="@appId">@appId</option>
}
}
</select>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="appKeyFormControlInput">AppKey</label>
</div>
<input type="text" class="form-control" id="appKeyFormControlInput" @bind="@appKey" @bind:event="oninput">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" @onclick="SetAppKey">Get AppKey</button>
</div>
</div>
代码部分
@code
{
private IEnumerable<string> appIds;
private string appId { get; set; }
private string appKey { get; set; }
protected override async Task OnInitializedAsync()
{
using HttpClient httpClient = new HttpClient();
var result = await httpClient.GetAsync("API_ADDR");
appIds = JObject.Parse(await result.Content.ReadAsStringAsync())["content"].ToObject<IEnumerable<string>>();
appId = appIds?.FirstOrDefault();
}
private async void SetAppKey()
{
using HttpClient httpClient = new HttpClient();
var result = await (await httpClient.GetAsync("API_ADDR")).Content.ReadAsStringAsync();
if (!string.IsNullOrWhiteSpace(result))
{
var app = JObject.Parse(result)["content"].ToObject<Application>();
appKey = app.AppKey;
}
}
}
期待
当我点击获取 AppKey 按钮时,input#appKeyFromControlInput 的值显示
当前AppId的appkey(input#inputGroupSelect)。
其实:
当我点击Get AppKey按钮时,input#appKeyFromControlInput没有反应;
当我再次点击 Get AppKey 时,input#appKeyFromControlInput 显示正确的 appkey。
环境:
- .NET 5 预览版 6
- Blazor WebAssembly
- Windows 10 2004
【问题讨论】: