我有一个页面,它使用 AddThis 进行链接分享和 Vue 进行渲染。现在,该页面显示了一个带有多个页面的链接列表。在第一页上,所有的分享都正常工作,但是在第二页上,它使用了第一页的链接。
以下是重现此问题的示例:
new Vue({
el: '#app',
data: {
pages: [
[{
url: 'http://google.com',
title: 'Google'
}],
[{
url: 'http://yahoo.com',
title: 'Yahoo'
}]
],
currentPage: 0
},
computed: {
items() {
return this.pages[this.currentPage]
}
},
methods: {
switchPage() {
if (this.currentPage === 0) {
this.currentPage = 1;
} else {
this.currentPage = 0;
}
}
}
})
<script src="https://unpkg.com/vue"></script>
<div id="app">
<div class="sharer" v-for="item in items">
<div class="addthis_inline_share_toolbox" :data-url="item.url" :data-title="item.title">{{ item.title }}</div>
</div>
<button @click="switchPage">Switch pages</button>
</div>
<script src="https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-57f620a4f185d54b"></script>
当处于第一页时,AddThis能正确分享Google主页。但是当处于第二页时,它无法获取用于分享Yahoo的data-*
标签。
注意:由于AddThis需要访问cookie,而沙盒iframe禁止此操作,因此您无法在此运行StackOverflow片段。可以在https://jsfiddle.net/d1az3qb3/3/找到运行版本。请记得禁用广告拦截器以使AddThis加载。
我已尝试过的事情
- 在切换页面后运行
addthis.layers.refresh()
- 运行
addthis.toolbox('.addthis_inline_share_toolbox')
(直接和在this.$nextTick(() => …)
中都试过)
问题
是AddThis出了问题,还是它与Vue不兼容,还是有办法让它正常工作?