what i need to do in domReady func or ...?
func (a App) domReady(ctx context.Context) {
}
and in index.html
<script></script>
Cant understand how to send data from go
to js
when dom ready and window is opened
Thx.
You have to define the Go function you want to call on the event DOMContentLoaded
as a member function of the App
structure, for instance:
func (a *App) OnDOMContentLoaded(arg1 string) string {
return arg1;
}
After compiling, this function will be available on the "frontend\wailsjs\go\main\App.js" file, and you can import it from your JS/TS files:
// assuming your JS file is in "frontend/src".
import {OnDOMContentLoaded} from '../wailsjs/go/main/App';
The compiled Go functions imported from JS return a promise with their return value. Then, inside your JS source, you just have to call the imported function on the listener of the DOMContentLoaded
event:
document.addEventListener('DOMContentLoaded', (event) => {
OnDOMContentLoaded('Hi!').then((result) => alert(result));
});