When interacting with native applications, we usually cannot see the data returned or printed by the native side in our local environment. In this case, we need to use a debugging tool. A very useful tool is vConsole, which allows us to clearly view network requests, console logs, and other information. It is similar to the browser’s DevTools (F12 console). Below is how to integrate it:
H5 Mobile Debugging Tool (vConsole for Mobile)
1 | <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js"></script> |
If you want to interact with the native side, you also need to use window. There are two scenarios: sending data and receiving data. Different approaches are used for different cases.
Case 1: Sending Data to the Native App
1 | if (window.webkit != undefined) { |
Case 2: Receiving Data from the Native App
1 | created() { |
When You Need to Redirect to the App via a Button
You can directly use an <a> tag with the href attribute to trigger the app, provided that the native application has defined a custom scheme such as:
1 | myapp://*** |
This works similarly to how Instagram handles H5-to-app redirection using a scheme like:
1 | instagram://** |
If the redirect does not work, it usually means the native app does not support the corresponding URL scheme.