In this project, you will learn how to dynamically display the homepage data using Vue.js. This project is designed to help you understand the process of fetching data from a JSON file and rendering it in a Vue.js component.
👀 Preview
🎯 Tasks
In this project, you will learn:
How to request the homepage post list data via Axios and bind it to the List.vue component.
How to implement the layout style and effect of the homepage to match the provided design.
🏆 Achievements
After completing this project, you will be able to:
Use Axios to fetch data from a JSON file.
Bind the fetched data to a Vue.js component and render it in the template.
Style the components to match a specific design.
Integrate different Vue.js components to create a complete homepage.
components/List.vue is the article list component to be added for this challenge.
public/static/data/list.json is the data file to get the list of articles.
public/static/images is the image file used for the list of articles.
Next, download the dependencies using the npm install command in the terminal, wait for the dependencies to finish downloading and then start the project using the npm run serve command.
Once the project starts successfully, click on the "Web 8080" to preview it in your browser. The running effect of the page is shown in the following image.
Completion of the List Display Function
In this step, you will learn how to request the homepage post list data via axios and bind it to the List.vue component.
Open the List.vue file located in the src/components folder.
Import the axios library under <script>:
// TODO
import axios from "axios";
In the data() function, define a dataList property to store the list data:
data() {
return {
dataList: []
};
}
In the created() lifecycle hook, call the getList() method to fetch the list data:
created() {
this.getList();
}
Implement the getList() method to fetch the data from the public/static/data/list.json file:
This step ensures that the homepage post list data is fetched from the public/static/data/list.json file and bound to the List.vue component.
By following these steps, you have completed the dynamization of the homepage data, including fetching the data from the public/static/data/list.json file and rendering the list items in the desired layout.
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy