### Handling Launch Errors and Events
Source: https://context7.com/syt-honey/h5-open-app/llms.txt
Illustrates how to listen for 'error' and 'launch' events on the openApp element. This is critical for implementing fallback logic, such as redirecting users to an app store if the app is not installed.
```javascript
const dom = await H5_APP({
wechatConfig: { appId: "wx123", timestamp: 1609459200, nonceStr: "str", signature: "sig" },
openTagConfig: { appid: "wxApp123", extinfo: "yt://page=home" }
});
if (dom !== -1) {
dom.mount(document.getElementById("container"));
dom.openApp.addEventListener("error", (e) => {
const errorDetail = e.detail;
console.error("唤起 App 失败:", JSON.stringify(errorDetail));
const isIOS = /iPhone|iPad/i.test(navigator.userAgent);
if (isIOS) {
window.location.href = "https://apps.apple.com/app/id123456789";
} else {
window.location.href = "https://play.google.com/store/apps/details?id=com.example.app";
}
});
dom.openApp.addEventListener("launch", (e) => {
console.log("成功唤起 App");
});
}
```
--------------------------------
### Vanilla JavaScript Integration
Source: https://github.com/syt-honey/h5-open-app/blob/main/README.md
Instructions and example code for integrating the h5-open-app library using Vanilla JavaScript.
```APIDOC
## Vanilla JavaScript Integration
### Description
Integrate the Whoa library into your H5 page using a script tag. This example demonstrates how to initialize and mount the app opening button.
### Method
Asynchronous function call
### Endpoint
N/A (Client-side script)
### Parameters
#### Request Body (Configuration Object)
- **openTagConfig** (object) - Required - Configuration for opening the app.
- **appid** (string) - Required - The App ID, found on the WeChat Open Platform.
- **extinfo** (string) - Required - Information for the page to open in the app (e.g., `yt://push.exclusive.co?page=xxx¶ms=xxx`).
- **wechatConfig** (object) - Required - WeChat authorization information.
- **appId** (string) - Required - Public account ID.
- **timestamp** (number) - Required - Timestamp for signature.
- **nonceStr** (string) - Required - Nonce string for signature.
- **signature** (string) - Required - Signature for WeChat authorization.
- **btnContainerStyle** (string) - Optional - CSS style for the button container.
- **btnStyle** (string) - Optional - CSS style for the button itself.
- **text** (string) - Optional - Text displayed on the button. Defaults to '打开APP'.
- **config** (object) - Optional - Library configuration.
- **debug** (boolean) - Optional - Enable debug mode. Defaults to `false`.
### Request Example
```json
{
"openTagConfig": {
"appid": "YOUR_APP_ID",
"extinfo": "your_app_scheme://path?param=value"
},
"wechatConfig": {
"appId": "YOUR_WECHAT_APP_ID",
"timestamp": 1678886400,
"nonceStr": "random_string",
"signature": "generated_signature"
},
"btnContainerStyle": "position: relative; width: 100px; height: 40px;",
"btnStyle": "background-color: blue; color: white;",
"text": "Open App",
"config": {
"debug": true
}
}
```
### Response
#### Success Response (Mount Object)
- **mount** (function) - Function to mount the generated button to a DOM element.
- **openApp** (HTMLElement) - The generated button element, with an event listener for 'error'.
#### Response Example
```javascript
// Assuming 'dom' is the result of H5_APP call
dom.mount(document.getElementById('button-container'));
dom.openApp.addEventListener('error', (e) => {
console.error('App opening failed:', e);
});
```
```
--------------------------------
### Whoa Configuration Object Structure
Source: https://context7.com/syt-honey/h5-open-app/llms.txt
Provides a comprehensive example of the configuration object required by the H5_APP function, detailing mandatory WeChat and App parameters as well as optional styling and debugging settings.
```javascript
const fullConfig = {
wechatConfig: {
appId: "wx1234567890",
timestamp: 1609459200,
nonceStr: "randomString",
signature: "sha1Signature"
},
openTagConfig: {
appid: "wxAppId123456",
extinfo: "scheme://path?param=value"
},
btnContainerStyle: "border-radius: 8px; overflow: hidden;",
btnStyle: "font-size: 16px; font-weight: 600; color: #ffffff; background: linear-gradient(90deg, #ff6b6b, #ff8e53);",
text: "在 App 中查看",
config: {
debug: false
}
};
const dom = await H5_APP(fullConfig);
```
--------------------------------
### Vue3 Component Integration
Source: https://github.com/syt-honey/h5-open-app/blob/main/README.md
Instructions and example code for integrating the h5-open-app library as a Vue3 component.
```APIDOC
## Vue3 Component Integration
### Description
Install the `@honeysyt/h5-open-app` package and use the provided Vue component to easily integrate the app opening functionality into your Vue 3 application.
### Method
Vue Component
### Endpoint
N/A (Client-side component)
### Parameters
#### Props
- **appConfig** (AppConfig) - Required - Configuration for opening the app.
- **appid** (string) - Required - The App ID, found on the WeChat Open Platform.
- **extinfo** (string) - Required - Information for the page to open in the app (e.g., `yt://push.exclusive.co?page=xxx¶ms=xxx`).
- **wechatConfig** (WechatConfig) - Required - WeChat authorization information.
- **app_id** (string) - Required - Public account ID.
- **timestamp** (string) - Required - Timestamp for signature.
- **nonce_str** (string) - Required - Nonce string for signature.
- **signature** (string) - Required - Signature for WeChat authorization.
- **text** (string) - Optional - Text displayed on the button. Defaults to '打开App'.
- **btnContainerStyle** (string) - Optional - CSS style for the button container.
- **btnStyle** (string) - Optional - CSS style for the button itself.
### Request Example
```vue