I'm a beginner to Vue, and I'm confused about why I cannot access a data property from within a method both on the same component. Every time I try to access my data by using 'this.items', it returns that 'items is undefined'.
I've tried changing the syntax of how I write the methods (I initially used an arrow function, but learning that it changes 'this', switched to a regular function definition), but it is still returning items as undefined.
Here is my full component with template:
<template>
<div>
<ul>
<li v-for="(item, index) in items" :key="index">
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
'items': []
};
},
methods: {
addItem: function(t) {
this.items.push(t)
}
},
}
</script>
This is just a simple todo list, and I have another component calling this function and passing the parameter to 'addItem()'.
Thanks!