diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index ee9e70bc063..eca0df8f6ea 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - + - 9.4.4 + 9.4.5-beta01 diff --git a/src/BootstrapBlazor/Components/IFrame/IFrame.razor.cs b/src/BootstrapBlazor/Components/IFrame/IFrame.razor.cs index 93873635207..bc211014249 100644 --- a/src/BootstrapBlazor/Components/IFrame/IFrame.razor.cs +++ b/src/BootstrapBlazor/Components/IFrame/IFrame.razor.cs @@ -6,30 +6,30 @@ namespace BootstrapBlazor.Components; /// -/// Frame 组件封装 Html iframe 元素 +/// Frame component encapsulates the Html iframe element /// public partial class IFrame { /// - /// 获得/设置 Frame 加载网页路径 + /// Gets or sets the URL of the webpage to be loaded in the Frame /// [Parameter] public string? Src { get; set; } /// - /// 获得/设置 需要传递的数据 + /// Gets or sets the data to be passed /// [Parameter] public object? Data { get; set; } /// - /// 获得/设置 Frame 加载页面传递过来的数据 + /// Gets or sets Frame loads the data passed by the page /// [Parameter] public Func? OnPostDataAsync { get; set; } /// - /// 获得/设置 页面加载完毕后回调方法 + /// Gets or sets Callback method after the page is loaded. /// [Parameter] public Func? OnReadyAsync { get; set; } @@ -40,6 +40,16 @@ public partial class IFrame private object? _lastData; + /// + /// + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + _lastData = Data; + } + /// /// /// @@ -59,17 +69,22 @@ protected override async Task OnAfterRenderAsync(bool firstRender) /// /// /// - protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, nameof(TriggerPostData)); + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new + { + Data, + TriggerPostDataCallback = nameof(TriggerPostData), + TriggerLoadedCallback = nameof(TriggerLoaded) + }); /// - /// 推送数据方法 + /// Method to push data /// /// /// public Task PushData(object? data) => InvokeVoidAsync("execute", Id, data); /// - /// 由 JavaScript 调用 + /// Called by JavaScript /// /// /// @@ -83,7 +98,7 @@ public async Task TriggerPostData(object? data) } /// - /// 由 JavaScript 调用 + /// Called by JavaScript /// /// [JSInvokable] diff --git a/src/BootstrapBlazor/Components/IFrame/IFrame.razor.js b/src/BootstrapBlazor/Components/IFrame/IFrame.razor.js index d9c5ffefa9d..53a68fb4a7a 100644 --- a/src/BootstrapBlazor/Components/IFrame/IFrame.razor.js +++ b/src/BootstrapBlazor/Components/IFrame/IFrame.razor.js @@ -1,16 +1,20 @@ import Data from "../../modules/data.js" -export function init(id, invoke, callback) { +export function init(id, invoke, options) { + const { data, triggerPostDataCallback, triggerLoadedCallback } = options; const handler = e => { - invoke.invokeMethodAsync(callback, e.data) + invoke.invokeMethodAsync(triggerPostDataCallback, e.data) } Data.set(id, handler) - window.addEventListener('message', handler); const frame = document.getElementById(id); frame.onload = () => { - invoke.invokeMethodAsync("TriggerLoaded"); + invoke.invokeMethodAsync(triggerLoadedCallback); + window.addEventListener('message', handler); + if (data) { + frame.contentWindow.postMessage(data); + } } }