E
E
Eugene2021-08-19 11:05:36
Vue.js
Eugene, 2021-08-19 11:05:36

How to dynamically access a property of a component's data object?

Tell me how you can access the component's data object, not directly, through this.varValueFirst, but dynamically, by converting the string into the name of this variable?

export default {
    data() {
        return {
            dynamicVarName: 'varValueFirst',
            varValueFirst: 'Значние1',
            varValueSecond: 'Значние2'
        }
    },   
    methods: {
        // Т.е. я хочу получить значение this.varValueFirst, но через значение переменной this.dynamicVarName 
        console.log(.....)
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-19
@atachrus

methods: {
    someMethod() {
        return this[this.dynamicVarName];
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question