简体   繁体   中英

How to use a third party theme in a server side blazor app?

I am trying to install a third party theme on a new server sided blazor app. https://startbootstrap.com/templates/sb-admin/

In order to get it working properly, I need to load the Javascript from the theme after I have got the rendered page because this JavaScript needs to work with the rendered elements from the DOM.

According to Google the OnAfterRenderAsync method should be the key to go but I don't know how I should do it the right way.

As per my guess, you need to add those *.js file references in index.html file.
And if there is any particular method that you want to execute after page render then you can use the JavaScript interop.

Index.html

<script>
  window.yourMethodName = (paraName) => {
    // ...
    // return something;
  };
</script>

Component.razor

@inject IJSRuntime JSRuntime;
//...
private async override Task OnAfterRenderAsync()
{
    var something = await JSRuntime.InvokeAsync<string>("convertArrayyourMethodName", paraName);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM