E
E
Erl2020-10-07 10:44:43
RESTful API
Erl, 2020-10-07 10:44:43

What is the right thing to do when creating an application in a query plan?

Good day.
I practice writing SPA, I took CMS Strapi as a basis and threw in a REST API, for one thing I decided to look at graphql (strapi gives out of the box)
a question arose, for example I have 3 models:
Articles - articles;
Categories - article categories;
Tags - something like hashtags, I will use it as a filter.
I also did the following, in the Navbar.vue component, I request all menu items through a vue-apollo request and display them, I do the same with tags, then Articles comes, I have a banner (the ArticlesBanner.vue component), where fresh 8 records are displayed , I also get them in a separate request, but I also need to display the rest of the entries on the page, and I also have categories where I should only display entries that contain this category.
The question itself is, am I doing the right thing by making a request in each component?
and should I make a request to display articles of a certain category?
Or is it worth getting all the data in vuex and filtering by categories and so on from there?
My request approach seems quite appropriate to me, since in the banner I don’t get all the articles, but only the first 8 that I need

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kitta, 2020-10-08
@NooBiToo

If you already have Vuex on the page, I would advise you to trust it to work with data. It's best to keep rendering components as little as possible aware of the infrastructure. Otherwise, after some time, you will no longer understand where the data comes from and how to coordinate them with each other.
But, of course, there is no universal solution, and in some cases it is better to receive data not at the page level (in Vuex or the root component), but directly in some separate component. For example, if it's just an independent widget on your page, or a temporary set to select one of the values ​​(the autocomplete function).
From the data, it is initially necessary to tighten the minimum necessary for the application to work. Data that in a significant number of cases may not be needed by anyone, it is better not to pull.

V
Vladimir Korotenko, 2020-10-07
@firedragon

Let Vuex think, and the components only display. Well, yes, getting more data than you need is a so-so idea. The maximum that can be done is prefetch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question