H5分享功能--带图标、说明
2024-09-18 21:11:07
代码实现
index.vue
<template>
<div id="app">
<SelfSharePage v-if="share_data.title" :shareInfo="share_data" /> <!-- 引用公用分享文件 -->
</div>
</template>
data() {
return {
share_data:{//动态获取需要描述的内容
img: "",
title:'',
intro:'',
},
};
},
SelfSharePage.vue
<template>
<div> </div>
</template> <script>
import wx from 'weixin-js-sdk'//引用微信分享插件
import {shareUrlApi} from "../../api/index"//后端获取分享条件参数 export default {
props:['shareInfo'],
data() {
return {
img:'',
title:'',
intro:'',
link:'',
};
},
methods: {
getWeiXinShare(s_img,s_title,s_intro,s_link){
this.$axios.post(shareUrlApi,{
url:window.location.href.split("#")[0]
}).then((res)=>{
if(parseInt(res.data.errCode)>=0){
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: res.data.data.appId, // 必填,公众号的唯一标识
timestamp: res.data.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.data.signature, // 必填,签名,见附录1
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage',
]
}); wx.ready(function () {
//分享到朋友圈
wx.onMenuShareTimeline({
title: s_title, // 分享时的标题
// link: window.location.href.split("#")[0], // 分享时的链接
link:s_link,
imgUrl: s_img, // 分享时的图标
desc: s_intro,
success: function () {
console.log("分享成功");
},
cancel: function () {
console.log("取消分享");
}
});
//分享给朋友
wx.onMenuShareAppMessage({
title:s_title,
desc: s_intro,
link: s_link,
imgUrl: s_img,
type: '',
dataUrl: '',
success: function () {
console.log("分享成功");
},
cancel: function () {
console.log("取消分享");
}
}); })
}
else{ }
}).catch((err)=>{
console.log(err)
})
}
},
mounted() {
this.img=this.shareInfo.img?this.shareInfo.img:'参数为空时默认图片'
this.title=this.shareInfo.title?this.shareInfo.title:'参数为空时默认标题'
this.intro=this.shareInfo.intro?this.shareInfo.intro:'参数为空时默认说明'
this.link=this.shareInfo.link?this.shareInfo.link:window.location.href.split("#")[0]
this.getWeiXinShare(this.img,this.title,this.intro,this.link)
}
};
</script> <style scoped> </style>
最新文章
- ubuntu14.04redis安装以及扩展
- 4. SVM分类器求解(2)
- Informatica - Powercenter 英文版资料(转载)
- Objective-C基础
- 转(linux shell)(2)
- 安装 Python
- Kali vmtools
- WPF中使用ValueConverter来实现“范围条件触发器”
- macos下使用rvm管理ruby版本和rails版本
- 016-类与对象-OC笔记
- [Swift]LeetCode703. 数据流中的第K大元素 | Kth Largest Element in a Stream
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.love5/com.example.love5.Main11Activity}: java.lang.NullPointerException: Attempt to invoke virtual method &#39;void android.
- java格式化
- .net EF之CodeFirst代码先行(转)
- uio.c 分析【转】
- Java-JUC(十):线程按序交替执行
- Mac系统常用快捷键
- 使用EntityFramework6完成增删查改CRUD和事务
- JS(微信小程序)处理银行卡号
- iOS自学-监听按钮点击、提醒框
热门文章
- CentOS下下查看硬盘型号、大小等信息(含Raid)
- BT做种
- StarRC 转XRC flow
- unity简单物理系统
- Pycharm报错:Error running ‘‘: Cannot run program “\python.exe“ (in directory ““)系统找不到指定文件夹?已解决!
- docker-compose任务编排
- Go组件库总结之介入式链表
- PR如何导出mp4格式的视频
- 关于protobuf报错&#39;tr1/unordered_map&#39; file not found
- VS2019使用Qt4.8.7