I
I
Ismail-12022-03-13 00:05:18
Vue.js
Ismail-1, 2022-03-13 00:05:18

How to properly get data in Vue?

Good evening!

<template>
    <div>
        {{regions.region1}} //Получаем объект {region: 'name'}
        {{regions.region}} //Пусто
    </div>
</template>

<script>
export default {
    name: "IndexCitySelect",
    data(){
        return {
            region: 'region1',
            regions: {
                region1: {
                    region: "name",
                 },
            },
        }
    }
}
</script>

Question about the block

{{regions.region1}} An object
is displayed {{regions.region}} //I expect to receive an object, but nothing is displayed, how can I output

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Koren, 2022-03-13
@IlyaMalone

You are accessing a property of an object that does not exist. The "regions" object has a property "region1" and this object also has a property: "region".
The "regions" object does not have a property: "region" that you are accessing, it only has "region1".
You must go through the chain: regions.region1.region;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question