vue项目中进行微博分享

1、首先要在页面写出点击可进行微博分享的入口,样式因自己项目而定:

<li class="bottomIcon_5 shareSina"><a href="javascript:;" target="_blank"></a><div class="shareTxt">微博</div></li>

2、其次,对微博按钮进行点击事件,也就是最重要的进行微博分享的操作:

// 微博分享
            $('.shareSina').on('click', function () {
                window.sharetitle = $(".print-tit").html();//分享的标题
                window.shareUrl = $(".myShare img").attr('src');//分享显示的图片
                share();
            })
            function share() {
                (function(s, d, e) {
                    try {} catch (e) {}
                    var f = 'http://v.t.sina.com.cn/share/share.php?',
                        u = window.location.href,
                        p = ['url=', e(u), '&title=分享的名称', '&pic=', e(window.shareUrl)].join('');
            
                    function a() {
                        if (!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=620,height=450,left=', (s.width - 620) / 2, ',top=', (s.height - 450) / 2].join(''))) u.href = [f, p].join('');
                    };
                    if (/Firefox/.test(navigator.userAgent)) { setTimeout(a, 0) } else { a() }
                })(screen, document, encodeURIComponent);
            }

点击后会出现一个新弹窗的页面,页面内含有你要分享的图片及网站的名称、详情等,页面会跳转到新浪微博,如果你已经登录微博,那么会直接分享成功,如果没有登陆,会跳转到登录页面,登陆后直接分享成功。

3、这样微博就分享成功了!