I am currently facing a challenge with Axios call in the Setup method of my component. My objective is to set a variable called "books". In Vue 2, I would execute the call within a created hook and utilize `this` to assign the variable. However, with Vue 3, `this` is not available in the setup method. So, my question is how can I access data outside the axios call? Specifically, my goal is to retrieve an array of books from the API and assign it to the "books" variable. What would be the best approach to achieve this in Vue 3? Below is a snippet of my setup method:
setup() {
let books = reactive<Array<Book>>([])
HTTP.get('/books')
.then(response => {
// Usually, I would use 'this.books' here
books = response.data
})
.catch(function (error) {
console.log(error);
})
return { books }
}