Reputation: 6157
I'm using Vuejs 3 with Typescript (and I'm new to all of it).
When I push a button, I want to get the tasks for a "to do" list.
This is my script:
<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
})
}
}
Simply writing this.tasks
gives me this error:
TS2339: Property 'tasks' does not exist on type '{ getTasks(): Promise ; }'.
How can I call a data property from a method?
Upvotes: 0
Views: 456
Reputation: 37753
When using TS, you need to define components like this:
import { defineComponent } from 'vue'
export default defineComponent({
...
})
Upvotes: 1