¿Cómo puedo convertir este script de Nuxt en uno compatible con Vue?
<script> export default { components: { FeaturedProduct }, async asyncData({ $axios }) { try { let response = await $axios.$get( 'http://localhost:5000/api/products' ) console.log(response) return { products: response.products } } catch (error) {} } } </script> ¿Cómo puedo hacerlo en Vue? Si quito el $ me da error diciendo
axios no definido
Esta sería la sintaxis en Vue (suponiendo que haya instalado axios para Vue)
<script> export default { async created() { try { let response = await this.axios( 'http://localhost:5000/api/products' ) console.log(response) this.products = response.data.products } catch (error) {} } } </script>Puede encontrar un ejemplo de trabajo aquí: https://github.com/kissu/vue2-axios/blob/master/src/App.vue