Error when using preserveState: true
See original GitHub issueWhen i call submitQuote() -> which calls the mutation setQuoteResult(); ‘this’ is undefined.
But it works when i remove preserveState: true
any ideas?
import {
VuexModule, Module, Mutation, Action, getModule,
} from 'vuex-module-decorators';
import { Inject } from 'inversify-props';
import { Quote, QuoteRequest, QuoteResult } from '@/models/quote';
import store from '@/store';
import TYPES from '@/types';
import IApplicationService from '@/services/IApplicationService';
@Module({ dynamic: true, store, name: 'quote', namespaced: true, preserveState: true })
export class QuoteModule extends VuexModule {
@Inject(TYPES.ApplicationService)
private applicationService!: IApplicationService;
quoteError: string = '';
quote: Quote = new Quote();
quoteResult: QuoteResult = new QuoteResult();
@Mutation
public setQuoteError(error: string): void {
this.quoteError = error;
}
@Mutation
public setQuote(quote: Quote): void {
this.quote = quote;
}
@Mutation
public setQuoteResult(result: QuoteResult): void {
// this is undefined
this.quoteResult = result;
}
@Action
public async fetchQuote(quoteId: string): Promise<Quote> {
try {
const result = await this.applicationService.getQuote(quoteId);
this.setQuote(result);
return result;
} catch (error) {
this.setQuoteError(error);
}
return new Quote();
}
@Action({ rawError: true })
public async submitQuote(request: QuoteRequest): Promise<QuoteResult> {
try {
const result = await this.applicationService.submitQuote(request);
// when calling this mutation
this.setQuoteResult(result);
return result;
} catch (error) {
this.setQuoteError(error);
}
return new QuoteResult();
}
}
export default getModule(QuoteModule);
export default new Vuex.Store({
strict: true,
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Manual visits - Inertia.js
The reload() method is simply a shorthand that automatically visits the current page, with preserveState and preserveScroll both set to true.
Read more >inertia get clearing my search input type - vue.js - Stack Overflow
Try using the { preserveState:true } option. Your code would like something like this: this.$inertia.get("/member", { term: this.term } ...
Read more >API Reference | Vuex
options can have preserveState: true that allows to preserve the previous state. Useful with Server Side Rendering.
Read more >@inertiajs/inertia-vue NPM | npm.io
Check @inertiajs/inertia-vue 0.8.0 package - Last release 0.8.0 with MIT licence ... preserveScroll: false, preserveState: true }) $inertia.put(url, data, ...
Read more >дэн on Twitter: "@glenathan The error boundaries won't preserve ...
That'll be the other major transform use-case ... The error boundaries won't preserve state though, I might need to put them right into...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Guys, be sure that you have correctly set index.ts. For example:
and module like this, when it doesn’t have a initial state and you load the state from the localStorage
@Module({ dynamic: true, store: store, name: 'mm', preserveState: localStorage.getItem('vuex') !== null })
i don’t use this lib anymore. maybe easier to just store what u need manually