【发布时间】:2021-09-28 06:54:16
【问题描述】:
我正在尝试将 Facebook cmets 插件 (check it here) 添加到我的 vue 应用程序中,问题是 div 是在 DOM 中创建的,但有时会显示,有时不显示(宽度:0,高度 0)
注意:我正在调用 XFBML.parse 函数,我的主机被添加到 fb 应用程序
这是我当前的代码:
<template>
<div
ref="commentContainer"
class="fb-comments"
:data-href="onUrl()"
:data-width="cwidth"
:data-numposts="numposts"
></div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted, watch } from "vue";
import router from "../../router";
export default defineComponent({
props: {
cwidth: {
type: String,
default: "100%",
},
numposts: {
type: String,
default: "2",
},
},
setup({ cwidth, numposts }) {
const commentContainer = ref(null);
const init = () => {
if (
window.FB &&
!commentContainer.value.hasAttribute("fb-xfbml-state")
) {
setTimeout(() => {
window.FB.XFBML.parse(commentContainer.value.parentElement);
}, 2000);
}
};
onMounted(() => {
setTimeout(() => {
init();
}, 1500);
});
const onUrl = () => {
return document.location.origin + document.location.pathname;
};
watch(
() => router.currentRoute.value,
() => {
init();
}
);
return { cwidth, numposts, commentContainer, onUrl };
},
});
</script>
【问题讨论】:
标签: javascript facebook vue.js plugins vuejs3