Thanks for reading my question.
I'm trying to get the new <script setup> syntax (Composition API) with Vue.js 3.2 and axios running.
With the normal syntax my code looks something like:
<script>
import axios from 'axios'
export default {
name: 'GetRequest',
data () {
return {
infos: null
}
},
mounted () {
axios
.get('https://api.predic8.de/shop/products/')
.then(response => (this.infos = response.data))
}
}
</script>
<template>
<div id="app">
{{ infos }}
</div>
</template>
This works just fine, but I use a template (https://github.com/justboil/admin-one-vue-tailwind) for my projekt which works with the new <script setup>.
I already found some solutions like:
<script setup>
import {onMounted} from "vue";
const {ref} = require("vue");
const axios = require("axios");
const info = ref([])
onMounted(async () => {
await axios
.get('https://api.predic8.de/shop/products/')
.then(response => {
this.info = response.data
})
})
</script>
<template>
<div id="app">
{{ infos }}
</div>
</template>
but it gives me 'this.infos' is assigned a value but never used.
Does anyone know how I can assigne the value to the variabel and call it in the <template>?
Update:
I found the solution by using infos.value instead of this.infos
<script setup>
import {onMounted} from "vue"
const {ref} = require("vue")
const axios = require("axios")
const infos = ref([])
onMounted(async () => {
await axios
.get('https://api.predic8.de/shop/products/')
.then(response => {
infos.value = response.data
})
})
</script>
<template>
<div id="app">
{{ infos }}
</div>
</template>
```