Creating the ListProducts component

Before we proceed with creating the filtering and ordering, we need to extract our product listing logic and template it into our component allowing us to easily reuse it. This component should accept a prop of products, which it should be able to list and paginate.

Open up the ListProducts.js file and copy the code from the HomePage.js file into the component. Move the data object and copy the pagination and pageLinks computed functions. Move the watch and methods objects, as well as the created() function, from the HomePage to the ListProducts file.

Update the HomePage template to use the <list-products> components with a products prop, passing in the products computed value. In comparison, the HomePage ...

Get Vue.js 2.x by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.