如图:
一: 安装share.js
npm install social-share.js
二:刚进来初始化
setTimeout(() => { this.setShare(); }, 0);
setShare() { let random = parseInt(Math.random() * 10000); this.urlParam = "http://www.xxxxxxx.com/share/index.html?stuWorkid=" + data+ "&schoolcode=" + this.$store.state.schoolcode + "&random=" + random; console.log(this.urlParam) //分享相关代码 window._bd_share_config = { common: { bdText: "我要分享", bdDesc: "我也要分享", bdUrl: this.urlParam }, share: [ { bdSize: 32 } ] }; console.log(window._bd_share_config) var s = document.createElement("script"); s.type = "text/javascript"; s.id = "scriptJs"; s.src = "http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=" + ~(-new Date() / 36e5); console.log(s.src) document.body.appendChild(s); window._bd_share_main.init(); }
三:布局
<div class="bdsharebuttonbox"> <img src="../assets/img/weixin.png" data-cmd="weixin" title="分享到微信"/> <img src="../assets/img/weibo.png" data-cmd="tsina" title="分享到新浪微博"/> <img src="../assets/img/gengduo.png" data-cmd="more" title="更多"/> </div>
----------END