H5利用微信开放标签唤起用户手机APP

2024-05-13 22:21

本文主要是介绍H5利用微信开放标签唤起用户手机APP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

APP壳子分享网页到微信,被分享人在微信打开网页后,利用公众号配置微信开放标签['wx-open-launch-app'],实现唤起APP

一、Vue2.x(2.6.11)

1. main.js

// main.jsimport Vue from 'vue';Vue.config.ignoredElements = ['wx-open-launch-app'];

2. awakeByWeChat.vue

// awakeByWeChat.vue
<template><wx-open-launch-appid="launch-btn":appid="公众号ID":extinfo="唤起app传递的参数"@error="onListenLaunchError"><script type="text/wxtag-template"><style>* {margin: 0;padding: 0;}button:focus {outline: none;}.defaultBtn {border: 0;height: 500px;outline: none;margin: 0 auto;font-weight: 500;}{{ btnStyle }}</style><button class="defaultBtn openBtn">{{ btnName }}</button></script></wx-open-launch-app>
</template><script>
export default {name: 'aweakAppByWeChat',props: {btnStyle: String, // 自定义按钮样式 `.btnClass{xx}`btnName: {type: String,default: '立即打开' // 自定义按钮名称}},data() {return {wxAppId: '',targetInfo: null, // 传递参数,格式需为字符串};},methods: {// wx 唤起失败异常处理, 降级处理跳转onListenLaunchError(e) {console.log('wx唤醒失败 | error', e.detail || e);this.$emit('launchError');}}
};
</script><style lang="less" scoped>
#launch-btn {position: absolute;top: 0;left: 0;right: 0;bottom: 0;opacity: 0;width: 100%;height: 100%;z-index: 99999;
}
</style>

二、Vue3.x(3.4.21)

1.main.js

// main.jsimport { createApp } from 'vue'const app = createApp(App)
app.config.compilerOptions.isCustomElement = (tag) => (tag.includes('wx-open-launch-app'))

2.vite.config.js

// vite.config.js
import { defineConfig } from 'vite'export default defineConfig({base: './',define: {__VUE_OPTIONS_API__: true // 关闭vue2中的 api属性},plugins: [vue({template: {compilerOptions: {isCustomElement: (tag:any) => tag.includes('wx-open-launch-app')}}})]
})

3.awakeByWeChat.vue

//awakeByWeChat.vue<template><wx-open-launch-appid="launch-btn":appid="props.wxId":extinfo="props.extinfo"@error="onListenLaunchError"><component :is="'script'" type="text/wxtag-template"><buttonstyle="display: block;border: 0;width: 100%;height: 500px;outline: none;margin: 0 auto;font-weight: 500;">{{ customName || "打开APP查看" }}</button></component></wx-open-launch-app>
</template><script lang="ts" setup>
const props = defineProps({wxId: {type: String,required: true,},extinfo: String,customName: String
});const emit = defineEmits(["launchError"]);const onListenLaunchError = (e) => {emit("launchError");console.log("WX唤起失败:", e.detail || e);// 执行降级操作
};
</script><style scoped lang="scss">
#launch-btn {position: absolute;top: 0;left: 0;right: 0;bottom: 0;opacity: 0;width: 100%;height: 100%;z-index: 99999;
}
</style>

这篇关于H5利用微信开放标签唤起用户手机APP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/986991

相关文章

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

Mysql中的用户管理实践

《Mysql中的用户管理实践》:本文主要介绍Mysql中的用户管理实践,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录13. 用户管理13.1 用户 13.1.1 用户信息 13.1.2 创建用户 13.1.3 删除用户 13.1.4 修改用户

使用Python和Tkinter实现html标签去除工具

《使用Python和Tkinter实现html标签去除工具》本文介绍用Python和Tkinter开发的HTML标签去除工具,支持去除HTML标签、转义实体并输出纯文本,提供图形界面操作及复制功能,需... 目录html 标签去除工具功能介绍创作过程1. 技术选型2. 核心实现逻辑3. 用户体验增强如何运行

详解如何在SpringBoot控制器中处理用户数据

《详解如何在SpringBoot控制器中处理用户数据》在SpringBoot应用开发中,控制器(Controller)扮演着至关重要的角色,它负责接收用户请求、处理数据并返回响应,本文将深入浅出地讲解... 目录一、获取请求参数1.1 获取查询参数1.2 获取路径参数二、处理表单提交2.1 处理表单数据三、

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

Mysql用户授权(GRANT)语法及示例解读

《Mysql用户授权(GRANT)语法及示例解读》:本文主要介绍Mysql用户授权(GRANT)语法及示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql用户授权(GRANT)语法授予用户权限语法GRANT语句中的<权限类型>的使用WITH GRANT

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32