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

相关文章

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

EMLOG程序单页友链和标签增加美化

单页友联效果图: 标签页面效果图: 源码介绍 EMLOG单页友情链接和TAG标签,友链单页文件代码main{width: 58%;是设置宽度 自己把设置成与您的网站宽度一样,如果自适应就填写100%,TAG文件不用修改 安装方法:把Links.php和tag.php上传到网站根目录即可,访问 域名/Links.php、域名/tag.php 所有模板适用,代码就不粘贴出来,已经打

EasyPlayer.js网页H5 Web js播放器能力合集

最近遇到一个需求,要求做一款播放器,发现能力上跟EasyPlayer.js基本一致,满足要求: 需求 功性能 分类 需求描述 功能 预览 分屏模式 单分屏(单屏/全屏) 多分屏(2*2) 多分屏(3*3) 多分屏(4*4) 播放控制 播放(单个或全部) 暂停(暂停时展示最后一帧画面) 停止(单个或全部) 声音控制(开关/音量调节) 主辅码流切换 辅助功能 屏

【Kubernetes】K8s 的安全框架和用户认证

K8s 的安全框架和用户认证 1.Kubernetes 的安全框架1.1 认证:Authentication1.2 鉴权:Authorization1.3 准入控制:Admission Control 2.Kubernetes 的用户认证2.1 Kubernetes 的用户认证方式2.2 配置 Kubernetes 集群使用密码认证 Kubernetes 作为一个分布式的虚拟

cell phone teardown 手机拆卸

tweezer 镊子 screwdriver 螺丝刀 opening tool 开口工具 repair 修理 battery 电池 rear panel 后盖 front and rear cameras 前后摄像头 volume button board 音量键线路板 headphone jack 耳机孔 a cracked screen 破裂屏 otherwise non-functiona

H5漂流瓶社交系统源码

一个非常有创意的H5漂流瓶社交系统源码,带完整前端h5和后台管理系统。 环境:Nginx 1.20.1-MySQL 5.6.50-PHP-7.3 代码下载

vue2实践:el-table实现由用户自己控制行数的动态表格

需求 项目中需要提供一个动态表单,如图: 当我点击添加时,便添加一行;点击右边的删除时,便删除这一行。 至少要有一行数据,但是没有上限。 思路 这种每一行的数据固定,但是不定行数的,很容易想到使用el-table来实现,它可以循环读取:data所绑定的数组,来生成行数据,不同的是: 1、table里面的每一个cell,需要放置一个input来支持用户编辑。 2、最后一列放置两个b

开放源许可证

https://opensource.org/licenses/category

MFC中App,Doc,MainFrame,View各指针的互相获取

纸上得来终觉浅,为了熟悉获取方法,我建了个SDI。 首先说明这四个类的执行顺序是App->Doc->Main->View 另外添加CDialog类获得各个指针的方法。 多文档的获取有点小区别,有时间也总结一下。 //  App void CSDIApp::OnApp() {      //  App      //  Doc     CDocument *pD

Spring下自定义xml标签

dubbo自定义了很多xml标签,例如<dubbo:application>,那么这些自定义标签是怎么与spring结合起来的呢?我们先看一个简单的例子。 一 编写模型类 1 package com.hulk.testdubbo.model;2 3 public class Hero {4 private String name;5 private int