On child components your data property should be a function that returns an object, like this
data () {
return {
//data here
},
)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
A User hasMany Card.php, within my first Component I am fetching all cards, to loop through them within my second Component, where I am getting the card prop, with the possibility to delete the card (below)
This is the CardComponent
<template>
<div>
<div>
<div>
<p>{{card.name}}</p>
<button @click="deleteCard(card.id)" class="button" v-model="card">-</button>
</div>
</div>
</div>
</template>
<script>
export default {
props: ['card'],
data() {
},
methods: {
deleteCard(cardId) {
const self = this;
axios.delete('/cards/' + cardId)
.then((response) => {
self.removeCard(cardId);
}).catch((response) => {
console.log(response);
});
},
removeCard(cardId) {
this.cards = _.remove(this.cards, (card) => { return card.id != cardId });
}
},
};
</script>
I am currently receiving this console error for fetching all Cards: Property or method "card" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
If I trigger the deleteCard method, I get: TypeError: target.$data is not an Object. (evaluating 'key in target.$data')
Any obvious mistakes within Vue?
On child components your data property should be a function that returns an object, like this
data () {
return {
//data here
},
)
Please or to participate in this conversation.