我使用Vuex从API获取帖子和评论。现在,我有:
mounted () {
this.$store.dispatch('getComments', this.post);
},
computed: {
comments () {
return this.$store.getters.orderedComments;
},
评论正文是一个包含HTML标记的字符串。我需要从给定类的href
标记中删除a
属性。
cleanUnwantedLinks () {
const link = document.getElementsByClassName('link-class')[0];
link.removeAttribute('href');
}
我不确定如何致电cleanUnwantedLinks
。应该在安装组件之后调用它(当我已经有注释时)。有办法吗?
答案 0 :(得分:0)
如果您要从getComments
行动中退回承诺,则可以执行以下操作:
this.$store
.dispatch('getComments', this.post)
.then(() => {
cleanUnwantedLinks()
/*
Can also try wrapping your call in $nextTick
this.$nextTick(() => { cleanUnwantedLinks() })
*/
});