0

当我在回调函数中时,我尝试在子组件中调用一个函数。

在我的子组件中:

<div class="container">
<h1 class="text-center">DUO BUSINESS</h1><i class="fal @IcoMenu" @onclick="CollapseMenu"></i>

@code{

        [Parameter]
        public EventCallback CollapseMenu { get; set; }

public void Popover()
    {
        Console.WriteLine("test");
    }
}

在我的父组件中:

     private void CollapseMenu()
    {
        if (collapseMenu == "vxs-left-side-menu")
        {
            this.collapseMenu = "vxs-left-side-menu vxs-left-side-menu-collapse";
            this.icoMenu = "fa-yin-yang";
        }
        else
        {
            this.collapseMenu = "vxs-left-side-menu";
            this.icoMenu = "fa-times";

------------HERE I WANT TO DO A FUNCTION IN CHILD COMPONENT------------
              Do popoverFunction in child component

        }
    }
4

1 回答 1

0

好的,我找到了答案:

在子组件中:

<div class="container">
    <h1 class="text-center">DUO BUSINESS</h1><i class="fal @IcoMenu" @onclick="Popover"></i>
</div>

    @code{

        [Parameter]
        public EventCallback CollapseMenu { get; set; }   


        public void Popover()
        {
            vxsMenuCollapsePopover = new string[5];
            CollapseMenu.InvokeAsync(true);
        }
    }

在父组件中:

<div class="@collapseMenu">
        <NavMenu CollapseMenu="@CollapseMenu" IcoMenu="@icoMenu"/>
    </div>

 private void CollapseMenu()
    {
        if (collapseMenu == "vxs-left-side-menu")
        {
            this.collapseMenu = "vxs-left-side-menu vxs-left-side-menu-collapse";
            this.icoMenu = "fa-yin-yang";
        }
        else
        {
            this.collapseMenu = "vxs-left-side-menu";
            this.icoMenu = "fa-times";
        }
    }

它现在对我有用如果你有更好的建议告诉我,谢谢!

于 2020-05-02T18:38:30.263 回答