P
P
prodavec macdonalds2018-09-18 18:03:40
Vue.js
prodavec macdonalds, 2018-09-18 18:03:40

Why isn't computed running?

Computed is executed only when I observe the component in vue devtools
More details
, there is a page, and there is a content (component) on it, there is a filter (component) in it, when choosing a selector with a country, the filter passes the country id to the main component, in which the computed through axios pulls the goods by country id. But after selecting country in computed selector if i don't select component content in vue devtools

computed: {
            coinYears () {
                if(this.coinsData.length>0)
                return this.coinsData
                .map((x) => x.year) // для каждого элемента из массива объектов data возвращаем год
                    .reduce((r, activeYear) => [...new Set(r.concat(activeYear))], []) // оставляем только уникальные значения
                    .map((activeYear) => { // для каждого элемента из полученного массива
                        // console.log(sadasdasd);                        
                        if((activeYear >= this.periodsStart) && (activeYear <= this.periodsEnd)) 
                            return { // возвращаем 
                                'year': activeYear, 
                                'coins': coinsDataByYear(activeYear, this.coinsData)
                            }
                        else
                            return false
                    
                })
            },
            getCountrys () {
                if(this.countryId)
                axios.post('/admin/coins/filter',
                        {"country_id": this.countryId}
                    )
                    .then(
                        response => (
                            this.coinsData = response.data
                        )
                    ); 
                    return this.coinsData;
            },
        },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-18
@prodavecmacdonalds

Strange code - strange behavior. Understanding the reasons for which is somehow not very interesting. Well, getCountrys shouldn't be a computed property, it shouldn't. It's a method, or possibly a watcher. Rewrite code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question