Complete the code to import the function used to make HTTP GET requests in Vue components.
<script setup> import axios from '[1]' </script>
Axios is a popular library to make HTTP requests, including GET requests, in Vue components.
Complete the code to define a reactive variable to store data fetched from a GET request.
<script setup> import { ref } from 'vue' const data = [1]([]) </script>
The ref function creates a reactive variable that can hold any value, including arrays.
Fix the error in the code to correctly fetch data with axios inside the onMounted lifecycle hook.
<script setup> import { ref, onMounted } from 'vue' import axios from 'axios' const users = ref([]) onMounted(async () => { const response = await axios.[1]('https://api.example.com/users') users.value = response.data }) </script>
The axios.get method is used to make GET requests to fetch data.
Fill both blanks to create a GET request inside the onMounted hook and assign the result to a reactive variable.
<script setup> import { ref, onMounted } from 'vue' import axios from 'axios' const posts = ref([]) onMounted(async () => { const response = await axios.[1]('https://api.example.com/posts') posts.[2] = response.data }) </script>
Use axios.get to fetch data and assign it to the reactive variable's value property.
Fill all three blanks to fetch data with axios, handle errors, and update reactive variables accordingly.
<script setup> import { ref, onMounted } from 'vue' import axios from 'axios' const items = ref([]) const error = ref(null) onMounted(async () => { try { const response = await axios.[1]('https://api.example.com/items') items.[2] = response.[3] } catch (err) { error.value = err.message } }) </script>
Use axios.get to fetch data, assign response.data to items.value, and catch errors to update error.value.