Consider a Vue component that uses Axios with a base URL set. What will be the full request URL when making a GET request to '/users'?
import axios from 'axios'; const apiClient = axios.create({ baseURL: 'https://api.example.com/v1' }); export default { methods: { fetchUsers() { return apiClient.get('/users'); } } };
Think about how Axios combines the base URL with the request path.
Axios appends the request path to the base URL. Since the base URL ends with '/v1' and the request path starts with '/users', Axios combines them correctly without duplicating slashes.
Identify the correct Axios configuration option to set a request timeout of 5000 milliseconds.
Look for the option that controls how long Axios waits before aborting a request.
The correct option is 'timeout'. It specifies the number of milliseconds before the request times out.
Examine the Axios request code below. Why might it cause a CORS error in the browser?
import axios from 'axios'; axios.get('https://api.example.com/data', { headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer token123' } }).then(response => { console.log(response.data); }).catch(error => { console.error(error); });
Check which options Axios supports and how CORS is handled in browsers.
The 'mode' option is a Fetch API option, not supported by Axios. Setting it has no effect. CORS errors are controlled by server headers and browser policies, not by Axios options.
Given the following Vue component method using Axios, what will be the value of this.responseData after the call?
import axios from 'axios'; export default { data() { return { responseData: null }; }, methods: { async loadData() { try { const response = await axios.get('https://api.example.com/items'); this.responseData = response.data.items; } catch (error) { this.responseData = []; } } } };
Consider what response.data.items represents and how errors are handled.
The method assigns response.data.items to responseData on success. On failure, it assigns an empty array. The data property is initialized as null but updated after the async call.
Choose the correct way to add a request interceptor in Axios that logs the request URL before the request is sent.
Recall the correct Axios interceptor syntax for requests.
The correct syntax is axios.interceptors.request.use(callback). Other options use invalid properties or methods.