@@ -19,8 +19,18 @@ public Vue3Renderer(IJavaScriptEnginePool javaScriptEnginePool) =>
1919 ".then(html => " + nameof ( SSRNetResultCallback ) + ".SetHtml('{2}','<div id={3}>' + html + '</div>'))" +
2020 ".catch(err => " + nameof ( SSRNetResultCallback ) + ".SetError('{2}','Error ' + err))" ; //componentName, propsAsJson, executionId, containerId
2121
22- private const string ClientHydrateScript = "createSSRApp({0}, {1}).mount({2})" ; //componentName, propsAsJson, id
23- private const string ClientRenderScript = "createApp({0}, {1}).mount({2})" ; //id, componentName, propsAsJson
22+ private const string ClientHydrateScript = "createSSRApp({0}, {1}){2}.mount({3})" ; //componentName, propsAsJson, ClientSideInjections, id
23+ private const string ClientRenderScript = "createApp({0}, {1}){2}.mount({3})" ; //id, componentName, ClientSideInjections, propsAsJson
24+ private string ClientSideInjections = "" ;
25+
26+ /// <summary>
27+ /// This makes it possible to inject functionality to an app before it is mounted. This will be rendered just before .mount("#app"). If you want
28+ /// to add a store that is available in a JavaScript variable named 'store' on the client side, then you would call this function with the string
29+ /// ".use(store)". This would render createApp(...arguments...).use(store).mount(...mount-point...)
30+ /// </summary>
31+ /// <param name="clientSideInjections"></param>
32+ public void SetClientSideInjections ( string clientSideInjections ) =>
33+ ClientSideInjections = clientSideInjections ?? "" ;
2434
2535 public async Task < RenderedComponent > RenderComponentAsync ( string componentName ,
2636 string propsAsJson ,
@@ -45,7 +55,7 @@ public async Task<RenderedComponent> RenderComponentAsync(string componentName,
4555 if ( html is null )
4656 return RenderComponentCSR ( componentName , propsAsJson ) ;
4757 result . Html = html ;
48- result . InitScript = string . Format ( ClientHydrateScript , componentName , propsAsJson , id ) ;
58+ result . InitScript = string . Format ( ClientHydrateScript , componentName , propsAsJson , ClientSideInjections ?? "" , id ) ;
4959 if ( sanitize )
5060 result . InitScript = result . InitScript . SanitizeInitScript ( ) ;
5161 return result ;
@@ -70,7 +80,7 @@ public RenderedComponent RenderComponentCSR(string componentName, string propsAs
7080 var result = new RenderedComponent
7181 {
7282 Html = string . Format ( CSRHtml , id ) ,
73- InitScript = string . Format ( ClientRenderScript , componentName , propsAsJson , id )
83+ InitScript = string . Format ( ClientRenderScript , componentName , propsAsJson , ClientSideInjections , id )
7484 } ;
7585 if ( sanitize )
7686 result . InitScript = result . InitScript . SanitizeInitScript ( ) ;
0 commit comments