【发布时间】:2018-06-28 19:43:44
【问题描述】:
所以我有一个使用 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 主页。但是在第二页时,它没有选择data-* 共享雅虎的标签。
注意:您不能在此处真正运行 StackOverflow sn-p,因为 AddThis 想要访问沙盒 iframe 禁止的 cookie。运行版本也可以在https://jsfiddle.net/d1az3qb3/3/ 找到。请记住禁用广告拦截器以让 AddThis 加载。
我已经尝试过的
- 切换页面后运行
addthis.layers.refresh() - 正在运行
addthis.toolbox('.addthis_inline_share_toolbox')
(直接和this.$nextTick(() => …))
问题
AddThis 是不是刚刚坏掉了,它与 Vue 不兼容还是有办法让它工作?
【问题讨论】:
标签: javascript vue.js addthis