Blazor子组件传递数据到父组件

@page "/counter"

<PageTitle>Counter</PageTitle>
<SubComponnent test="returnDatas"></SubComponnent>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }


    private void returnDatas(string test){

        var x = test;


    }


}

  

<h3>SubComponnent</h3>



<button @onclick="aaaa">test</button>


@code {


    [Parameter]
    public EventCallback<string> test { get; set; }


    private async void aaaa()
    {
        await test.InvokeAsync("hahahaha");

    }
}

  

posted @ 2023-02-08 10:34  面无表情的石头  阅读(98)  评论(0)    收藏  举报