【发布时间】:2021-02-25 18:43:04
【问题描述】:
我正在尝试在 Blazor 的子组件内双向绑定文本区域,但我无法弄清楚。
家长
@page "/test"
<h3>Parent Component</h3>
<input type="text" @bind="mydata" />
<TWBTextArea @bind-ChildData=@mydata></TWBTextArea>
@code {
public string mydata = "test";
}
儿童
<h4>Child Component</h4>
<textarea @bind=@ChildData></textarea>
@code {
[Parameter] public string ChildData { get; set; }
[Parameter]
public EventCallback<string> ChildDataChanged { get; set; }
}
当我从父组件更新时,子文本区域更新,但是当我更新子文本区域时,父组件没有更新。
附加说明:如果我将传递的值从 string 更改为具有字符串属性的 对象 并将该对象传递给子组件,则双向绑定确实有效,但只有在更新父组件之后。
提前感谢您的帮助!
【问题讨论】:
标签: c# asp.net-core blazor