Перехватываю id из строки браузера и пытаюсь получить запись из массива находящегося в $store по id, в браузере в консоли ошибок нет, но геттер явно не работает. Код из state файла:
state: {
ads: [
{
title: 'First ad',
description: 'fake description chip and dale eat nuts',
promo: false,
imageSrc: 'https://cdn.vuetifyjs.com/images/carousel/squirrel.jpg',
id: 1234
},
{
title: 'Second ad',
description: 'Eagle eat his nogti',
promo: true,
imageSrc: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
id: 2345
},
{
title: 'Third ad',
description: 'fake description',
promo: true,
imageSrc: 'https://cdn.vuetifyjs.com/images/carousel/sky.jpg',
id: 3456
}
]
},
getters: {
adById (state) {
return adId => {
return state.ads.find(ad => ad.id === adId)
}
}
}
}
Код компонента:
<template>
<v-container>
<p>{{ad}}</p>
</v-container>
</template>
<script>
export default {
props: ['id'],
computed: {
ad () {
return this.$store.getters.adById(this.id)
}
}
}
</script>
Если вставляю в computed свойство строку
console.log(this.$store.getters.adById(this.id)) То в браузере выводит undefined
Подскажите где ошибка?
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости