javascript - vue組件中使用百度分享初次加載失敗?
問題描述
我的vue項目中使用了百度分享,代碼如下template中
js(放在created中)

初次加載時,百度分享的按鈕圖片都不顯示,F(xiàn)12發(fā)現(xiàn)class和點擊事件都未生效刷新后就正常顯示使用

在mounted中使用this.$nextTick,也有點問題
mounted() {
let _this = this;this.$nextTick(function () { window._bd_share_config = {common : { bdText : _this.art.title, bdDesc : _this.art.abstract, bdPic : 'http://www.jubao56.com/upload_admin/2016-07-05%2010:08:50-banner4_m.jpg',},share : [{ tag:'share_0', bdSize : 24}], }; 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);}) },
問題解答
回答1:js寫在 mounted事件里,this.$nextTick(() => { ...... });
百度分享的 js可能會 立即執(zhí)行并查找DOM元素。created事件觸發(fā)時,并不存在DOM
相關(guān)文章:
1. javascript - ionic1的插件如何遷移到ionic2的項目中2. python小白 自學看書遇到看不懂的地方3. javascript - immutable配合react提升性能?4. javascript - 在vue項目中遇到的問題:DOMException5. php對mysql提取數(shù)據(jù)那種速度更快6. shell - mysql更新錯誤7. javascript - vue中使用prop傳遞數(shù)據(jù)問題8. python - 在github上看到一個基于卷積神經(jīng)網(wǎng)絡提高圖片分辨率的小項目waifu2x??9. 如何設置一個無限循環(huán)并打破它。(Java線程)10. 網(wǎng)頁爬蟲 - 如何使用使用java抓取信息并制作一個排名系統(tǒng)?

網(wǎng)公網(wǎng)安備