Change this
props() {
['parentCategory']
},
with this
props: ['parentCategory'],
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I've started to work with Vue Js and I don't understand how the accessing of data and propeties works. I've got a very basic Vue component that fires a method when you press enter. Basically I want to send a post request with A: the value of the textfield (got that to work) and B: the value of a property I'm giving in the html tag (parentCategory) . I can't seem to access the parentCategory property. I know you would access it in the template like you would any data but when I console.log the value of the parentCategory It's undefined.
<script>
export default
{
data() {
return {
category: {
name: '',
category_id: ''
},
showfield: false
}
},
props() {
['parentCategory']
},
methods: {
createCategory() {
console.log(this.parentCategory)
this.category.category_id = this.parentCategory
console.log(this.category.category_id)
this.$http.post('/categories', this.category).then((response) => {
console.log('received')
}, (response) => {
console.log('failed to store')
//Remember that this might not fire if the backend failed.
});
}
}
}
</script>
What am I missing here? Is there a different way to access properties in component methods?
Please or to participate in this conversation.