鍍金池/ 問(wèn)答/網(wǎng)絡(luò)安全  HTML/ vue怎么用百度分享

vue怎么用百度分享

vue用百度分享具體該怎么用啊,我把js相關(guān)代碼寫在了mounted的鉤子里,并且是setTimeout()執(zhí)行的,但是原本代碼的樣式有時(shí)候生效有時(shí)候就不生效,很不穩(wěn)定啊~~~~
clipboard.png
生效時(shí)的樣子如上,不生效的樣子如下:

clipboard.png

這是什么原因?qū)е碌哪兀?/p>

mounted(){
        setTimeout(()=>{
          window._bd_share_config = {
            "common": {
              "bdSnsKey": {},
              "bdText": "有一款寶貝推薦給你",
              "bdMini": "2",
              "bdMiniList": false,
              "bdPic": "2.jpeg",
              "bdStyle": "0",
              "bdSize": "0"
            },
            "share": {}
          };
          with(document)0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~ ( - new Date() / 36e5)];
        },0)
    },
回答
編輯回答
舊酒館

別在mounted掛載完成之后鉤子寫

試試在beforeMount 掛載之前寫

2017年1月18日 20:12
編輯回答
離夢(mèng)

試了那么多種方法都不行,自己觀察了一下,解決了。就是要加上class bdshare-button-style0-16

 <template>
       <div class="bdsharebuttonbox bdshare-button-style0-16">
           <a href="#" class="bds_more" data-cmd="more"></a>
           <a href="#" class="bds_qzone" data-cmd="qzone"></a>
           <a href="#" class="bds_tsina" data-cmd="tsina"></a>
           <a href="#" class="bds_tqq" data-cmd="tqq"></a>
           <a href="#" class="bds_renren" data-cmd="renren"></a>
           <a href="#" class="bds_weixin" data-cmd="weixin"></a>
        </div>
    
    </template>
    
    <script>
    export default {
    beforeCreate(){
        const _this=this;
        setTimeout(()=>{
            _this.setup()
        },0)
    },
    methods:{
        setup(){      
            window._bd_share_config={
                "common":{
                    "bdSnsKey":{},
                    "bdText":"",
                    "bdMini":"2",
                    "bdPic":"",
                    "bdStyle":"0",
                    "bdSize":"16"
                },
                "share":{},
                "image":{
                    "viewList":["qzone","tsina","tqq","renren","weixin"],
                    "viewText":"分享到:","viewSize":"16"
                },
                "selectShare":{
                    "bdContainerClass":null,
                    "bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]
                }
            };
            const s = document.createElement('script');
            s.type = 'text/javascript';
            s.src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5);
            document.body.appendChild(s);
        }
    }
    }
    </script>

2017年11月18日 20:41
編輯回答
尛曖昧

試試這樣:

mounted(){
    this.$nextTick(function () {
    // 執(zhí)行函數(shù)
    })
}

或者把setTimeout的時(shí)間設(shè)置為20試試,一般瀏覽器更新周期為18ms

2017年7月15日 09:59
編輯回答
墻頭草

貼代碼看看啊

2018年4月30日 21:16