P粉5471709722023-09-02 10:45:09
As I mentioned in the comments, passing objects as query parameters is not a popular way, so there are two ways to do it -
method 1-
Pass only the cve_id
to the new route and when installing the new route's page, use this query parameter cve_id
to get the cve_object
from the backend.
This approach is useful and recommended because you always get updated data from the backend.
If you follow this approach, there are a few changes that need to be made -
cve_id
to your new route -methods: { onAboutClick(cve_id) { this.$router.push({ name: "clickthru", query: { cve_id: cve_id }, }); }, },
clickthru.vue
installed hook, initialize the API call to get the cve_data
-mounted() { // Make an API call to fetch the respected id's data }
Method 2-
When you receive a record in HomePage.vue
(the one you are looping over), save this data to your Vuex state. Now, same as method one, just pass the cve_id
to the new route and get it from the Vuex state when the new route's page is installed, rather than from an additional API call.
If you follow this approach, the process will be like this -
const store = new Vuex.Store({ state: { records: [] }, mutations: { SET_RECORDS (state, backend_response) { // mutate state state.records = backend_response; } } })
cve_id
in your route query, so you can use it to get the relevant cve_object
from the state. So after installing clickthru.vue
do the following -<script> export default { data() { return { cve_object: null, }; }, mounted() { this.cve_object = this.$store.state.records.find( (item) => item.id == this.$route.query.cve_id, ); }, }; </script>
This way you will have your records in that state, so you can use the query cve_id
on any page to find any single record.
Notice-
I only give the idea of getting and setting data from state. If you want to take the second approach, just read Vuex and follow the documentation.
You can also check out the complete guide here How to setup Vuex in a Vue application.