-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading state async #20
Comments
Well, Loading the state dynamically would be a feature to implement. It is not really in my priorities but anybody could do it easily - I will still check if I couldn't do it really fast. If not, a workaround is this one : |
Wow - ok. Indeed no, it will not be implemented for the simple fact that golden-layout does not have it implemented neither. Also, the guards can be used also for the same purpose : to call the |
Thanks.. Here are tidbits of what I ended up with. I have to reload the whole page, tho, but thats ok for this simple usecase.
|
Indeed, I was not seeing how to do without a reload with the guards, hence my idea of using the route functionalities. Here, I quickly made a draft - that case can unfortunately not be used in my test application (as routes are used inside the golden-layout) So, the component would have a constructor with a state parameter : <template>
<golden-layout @state="changedState" :state="state">
<something />
</golden-layout>
</template>
<script lang="ts">
import Vue from 'vue'
import {Component, Inject, Model, Prop, Watch} from 'vue-property-decorator'
@Component()
export default class MyLayout extends Vue {
state: any
constructor(state) {
this.state = state;
}
changedState(state) {
axios.put(...);
}
...
}
</script> And here would be the definition of the route : {
path: `/MyLayout`,
component: ()=> axios
.get(`https://domain/api/v1/layouts/${name}/`)
.then(response => {
return new MyLayout(response.data.gl);
})
.catch(error => {
Notify.create({
message: "Unable to load layout..",
detail: error.message
});
throw error; //To be sure Vue knows the component load has failed
});
})
} |
I'm trying to load the initial state using axios, but I think it is too late to load the state when axios are able to get it from the backend.
Based on what I can read in the source, everything in
vue-golden-layout
that deals with loading the state happens in themounted()
function.. I have been playing with vue route-guard (beforeRouteEnter
), the only place I can populatethis
, would be after thevue-golden-layout
is already loaded..Will using a guard (https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards) be a way? Is there a complete other way of doing this? Or am I missing something?
I guess setting localStorage inside a guard might work.. But now sure if that is the way to do it..?
The text was updated successfully, but these errors were encountered: