我弄乱了你的小提琴,想到了这个:
let Projects = {
template: `<v-expansion-panel >
<v-expansion-panel-content ripple v-for="project in filteredProjects "
:key="project.id" lazy><div slot="header"
@click="loadSpaces(project)">{{project.name}}</div>
<v-card>
<v-card-text v-if="loading == true" class="grey lighten-3" >
<v-btn flat block
v-for="space in spaces" :key="space.id"
@click="loadLayout(project)">{{space.id}}</v-btn>
</v-card-text>
</v-card>
</v-expansion-panel-content>
</v-expansion-panel>`,
components: {
Spaces,
},
props: {
searchFilter: String,
},
data: () => ({
data: uniBuilderProjects.state,
loading: false,
}),
computed: {
filteredProjects: function() {
var self = this;
return self.data.projects.filter(function(project) {
return (
project.name
.toUpperCase()
.indexOf(self.searchFilter.toUpperCase()) !== -1
);
});
},
spaces: function() {
return this.data.spaces;
},
},
methods: {
loadSpaces: function(project) {
this.loading = false;
console.log(this.loading);
uniBuilderProjects.loadSpaces(project.id);
this.loading = true;
},
},
mounted: function() {
// Load Projects
uniBuilderProjects.loadProjects();
this.$devices = this.$resource(
'https://jsonplaceholder.typicode.com/posts{/id}/comments',
);
},
};
所以我使用了条件渲染,每当函数完成时,就设置这个。加载至true和boom。不确定这是否是最好的方法,但似乎是一个快速的解决方案。