New to Vuejs 3 and Typescript here. I have a button that should fetch tasks for a "to do" list when clicked. Below is the script I'm using:
<script lang="ts">
import axios from 'axios';
export default {
name: 'Todos',
data() {
return {
tasks: Array<Task>(),
}
},
methods: {
async getTasks() {
await axios.get('https://.../tasks').then(response => {
this.tasks = response.data
})
}
}
But when I try writing this.tasks
, I encounter an error:
TS2339: Property 'tasks' does not exist on type '{ getTasks(): Promise ; }'.
Any ideas on how to access a data property from within a method?