Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Axios in a Vue component.
Vue
import [1] from 'axios';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Axios' instead of lowercase 'axios'.
Trying to import 'http' or 'fetch' which are different libraries.
✗ Incorrect
The correct import name for Axios is axios with a lowercase 'a'.
2fill in blank
mediumComplete the code to create an Axios instance with a base URL.
Vue
const api = axios.[1]({ baseURL: 'https://api.example.com' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' keyword which is not how Axios instances are created.
Using 'createInstance' or 'init' which are not valid Axios methods.
✗ Incorrect
The method to create a new Axios instance is create.
3fill in blank
hardFix the error in setting a default header for the Axios instance.
Vue
api.defaults.headers.common['[1]'] = 'Bearer token123';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'authorization' which may cause issues in some environments.
Using 'Auth' or 'Token' which are not standard header names.
✗ Incorrect
The correct header name for bearer tokens is Authorization with uppercase 'A'.
4fill in blank
hardFill both blanks to add a request interceptor that logs the request URL.
Vue
api.interceptors.[1].use(config => { console.log(config.[2]); return config; });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'response' instead of 'request' for intercepting outgoing requests.
Logging 'baseURL' instead of 'url' which may not show the full request path.
✗ Incorrect
To intercept requests, use request interceptor and log the url property from the config.
5fill in blank
hardFill all three blanks to create a GET request with Axios and handle the response.
Vue
api.[1]('/users') .then(response => { console.log(response.[2]); }) .catch(error => { console.error(error.[3]); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for a GET request.
Trying to access 'response.body' which is not how Axios returns data.
Accessing 'error.data' instead of 'error.message' for error details.
✗ Incorrect
Use get to make a GET request, access data from the response, and message from the error.