B
B
BonBon Slick2021-07-25 20:01:22
typescript
BonBon Slick, 2021-07-25 20:01:22

Vue + Typescript dynamic action/getter namespace?

@Template
@Component<ComponentClass>(
    {
        components: {},
        mixins:     [],
        directives: {},
    },
)
export default class ComponentClass extends Vue
    @Prop({ type: String, required: true })
    dynamicNamespaceProp!: string[];
    
    @namespace(dynamicNamespaceProp).Getter
    someGetter!: { [key: string]: string };

    get dynamicNamespace() : string {
        return  this.dynamicNamespaceProp;
    }
    mounted(): void {
    }

};


Cannot find name 'dynamicNamespaceProp'.

In regular Wu, you can implement dynamic getters and actions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BonBon Slick, 2021-07-27
@BonBonSlick

@Prop({type: String, required: true})
    namespace!: string;

    get currentStep(): any {
        return store.getters[`${this.namespace}/currentStep`];
    }

versus
computed: {
        ...mapState(`${LISTS}/${PUBLIC_NOT_SECURED}`, {
            // dynamic getters
            // DO NOT MODIFY "RVALUE"!
             list(state, getters) {
                return getters[`${this.namespace}/list`];
             },

setFieldValueByFieldNameFromEvent ($event: InputEvent): Promise<object>{
        return  store.dispatch(`${this.namespace}/setFieldValueByFieldNameFromEvent`, $event);
    }

I will say right away that the solution is extremely crutch like the whole vue 2 + ts, if only because the entire storage in the component is imported, which can slow down the application by 5+ seconds when the component is mounted on old mobiles. But this solves the problem, I tried a bunch of options avoiding this, alas.
The second variant without TS is a map of a specific getter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question