I'm running a nuxtjs app which displays data from wordpress. On my project overview page I want to have the images of the different projects displayed as masonry with isotope and filtering. When I open the website on root and navigate to the project page (/project) everything is displayed correctly. When I reload the page or type in the URL manually, the layout is crashed. After some error handling I found out that on page reload isotope wants to layout the unloaded project data. On page enter - "projekte geladen." On reload / manually - "keine projekte".
Code:
<script>
/* eslint-disable */
let Isotope;
let imagesLoaded;
if (process.client) {
Isotope = require('isotope-layout');
imagesLoaded = require('imagesloaded')
}
export default {
mounted() {
this.isCaseStudy();
this.isotope();
},
computed: {
page(){
//return this.$store.getters.filterProject;
return this.pages.find(page => page.id === 110)
},
pages(){
return this.$store.state.pages;
},
projects(){
return this.$store.state.projects;
},
},
created(){
this.$store.dispatch("getPages");
this.$store.dispatch("getProjects");
},
methods: {
isCaseStudy(){
$(".item").each(function(){
$(this).has('img.case-studyImg').addClass('case-study');
});
},
isotope() {
console.log("isotope wird ausgeführt");
if(this.projects.length != 0){
console.log("projekte geladen!")
let iso = new Isotope('.items', {
itemSelector: '.item',
masonry: {
columnWidth: '.grid-sizer'
}
});
imagesLoaded(".items").on( 'progress', function() {
// layout Isotope after each image loads
console.log("each image loaded");
iso.layout();
});
}else{
console.log("keine projekte");
}
},
filterItems(selector) {
let oldActive = $(".filters .btn-primary").first();
console.log(oldActive);
if(oldActive.hasClass(selector)){
return;
}
let currentActive = $(".filters a." + selector).first();
console.log(currentActive);
currentActive.removeClass("btn-default").addClass("btn-primary");
oldActive.removeClass("btn-primary").addClass("btn-default");
iso.arrange({filter: `.${selector}`});
}
}
}
</script>
So on reload the function this.isotope() is loaded before the projects() from computed loaded I believe. How can I accomplish that isotope loads when the projects are loaded if thats the real problem for this...