Nativescript-vue: How to get the webViewModule ?

Created on 20 Mar 2018  路  3Comments  路  Source: nativescript-vue/nativescript-vue

How to get webViewModule in the nativescript-vue, If I want to listen loadFinishedEvent action?
I can't get the webViewModule , console output undefined. That is my code as follow :

   <template>
    <Page ref="page" class="page">
        <ActionBar class="action-bar" title="CAS鐧诲綍"> </ActionBar>
        <StackLayout>
            <WebView id="webView" :src="src" />
        </StackLayout>
    </Page>
   </template>
  import webViewModule from "tns-core-modules/ui/web-view";

  export default {
       data() {
           return {
               src: 'https:www.google.com'
           };
        },
        mounted() {
            let page = this.$refs.page.nativeView;
            let webView = page.getViewById('webView');
            console.log("webViewModule");
            console.log(webViewModule);
            webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
             let message;
             if (!args.error) {
                      message = "WebView finished loading " + args.url;
               }
               else {
                message = "Error loading " + args.url + ": " + args.error;
               }
             });

         }
    }; 
question

All 3 comments

The easiest would be to attach a loadFinished event listener to the webview directly:

 <template>
    <Page ref="page" class="page">
        <ActionBar class="action-bar" title="CAS鐧诲綍"> </ActionBar>
        <StackLayout>
            <WebView @loadFinished="onLoadFinished" :src="src" />
        </StackLayout>
    </Page>
 </template>
{
 // ...
  methods: {
    onLoadFinished(args) {
      let message;
      if (!args.error) {
        message = "WebView finished loading " + args.url;
      } else {
        message = "Error loading " + args.url + ": " + args.error;
      }
    }
  }
}

But otherwise I think you need to use the import like this:
import * as webViewModule from "tns-core-modules/ui/web-view";

As you say, I used the @loadFinished="onLoadFinished" event listener , and I caught the url. thank you very much.

However, I still can't import the webViewModule , like this import * as webViewModule from "tns-core-modules/ui/web-view";

it will cause something wrong, but nothing output in terminal console . I use vue-cli create the project by nativescript-vue/vue-cli-template .

The tns-core-modules/ui/web-view is seems to be .ts file. Maybe webpack.config.js is not configured any typescript loader ???

There are ts files, but when it is installed through npm you will get .js files like web-view.android.js and web-view.ios.js these will get imported automatically when running on the device.

I just tried import * as webViewModule from "tns-core-modules/ui/web-view"; and it works as expected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justinbeatz picture justinbeatz  路  3Comments

packytagliaferro picture packytagliaferro  路  5Comments

farfromrefug picture farfromrefug  路  5Comments

Fabiyo-90 picture Fabiyo-90  路  6Comments

vhristov5555 picture vhristov5555  路  4Comments