Notalib / nativescript-webview-ext

Nativescript plugin with extended WebView functionality
Apache License 2.0
76 stars 37 forks source link

Execute vue method on server-side via webviewext #82

Open giulianimartini opened 4 years ago

giulianimartini commented 4 years ago

Hi,

how can I execute a Vue method on my server-side code called by my Nativescript app?

In my server-side I have a vue method called refreshPage() and I want to execute it by calling it from the NS app. I have read about emitToWebView in the documentation, but I can't find any example on this.

I am using version 6.5.2 of webviewext: "@nota/nativescript-webview-ext": "^6.5.2";

Can you help me?

Thanks in advance.

giulianimartini commented 4 years ago

Hi,

I managed it by doing a click on my refreshButton (then I just update the reactive data on server-side (vue)):

let webView = this.$refs.webViewReservas.nativeView;

const refreshButton = `document.getElementById('refreshButton').click();`;
webView.executeJavaScript(refreshButton);

It would be nice if someone manage to solve it in another way (like calling the vue method directly).

m-abs commented 4 years ago

It is very hard to help without a more complete code example, showing the problem.

I don't know anything about Vue, making it even harder to help.

giulianimartini commented 4 years ago

Hi @m-abs,

Thanks for your time.

My scenario is like this:

I have a server-side code that refreshes the page.

methods: {
    refreshPage() {
        window.location.reload();
        //instead of reload, I call other vue methods here, so window.location.reload() will be replaced by other vue methods.
    }
}
methods: {
    executeRefreshPageOnServerSide() {
        let webView = this.$refs.webViewReservas.nativeView;

        //I want to access the refreshPage() vue method on server-side by the webview reference.
    }
}

Note: if the refreshPage() method is in a <script> tag, it works, but that isn't my case. It's in a vue instance inside the methods (to listen to DOM events).

m-abs commented 4 years ago

It would be much better, if you create a small test project demonstrating the problem. Either as a github repo or attached as a zip-file.