Is there an event in Vue that fires after an element is re-rendered? I have an object that updates, which causes my template to update. After the update, I want to trigger an event that fires the jQuery function. The code is as follows:
template: `
<div class="undo-margin">
<div class="gradient">
<img v-bind:src="blogPost.thumbnail"/>
<h1 class="align-bottom">{{blogPost.title}}</h1>
</div>
<div class="container bg-faded">
<article v-html="blogPost.article"></article>
</div>
</div>
`,
props: ["blogid"],
data: function () {
return blogPageData;
},
mounted: function () {
const blogid = jQuery("#blogPage").attr("blogid");
if (this.authdata.roles.indexOf("Administrator") !== -1) {
this.isAdmin = true;
}
this.getBlogPost(blogid);
},
methods: {
getBlogPost: function (blogid) {
var element = this;
$.ajax({
url: `/api/blog/${blogid}`,
type: "get",
headers: headers,
success: function (data) {
if (data === undefined) {
window.location.replace("/blog");
} else {
element.isDetails = true;
element.blogPost = data;
}
},
error: function (data) {
window.location.replace("/blog");
errorData.error = data.responseText;
}
});
}
},
watch: {
blogPost: function () {
console.log(this.blogPost);
jQuery("pre").each((i, e) => {
hljs.highlightBlock(e);
});
}
}
As you can see, I tried to use the watch event, however, when the watch event was fired, my page is not yet updated. blogPost, however, has been changed, but vue still displays the page. I know that I can theoretically fix this by adding setTimeout, but I would prefer something cleaner.
source
share