Guide to transferring array information from one Vuejs route to another

I'm facing an issue with passing an array from one Vuejs route to another. Specifically, I need to pass the array from home.vue to post.vue.

In my route.js file for post.vue, I have:

{
  path: '/post/:cart',
  name: 'post',
  component: PostView,
  props: true
}

This is how I've structured my home.vue:

<router-link to="/post/:cart">Check out</router-link>

And in my post.vue:

props: ['cart'],
mounted () {
    console.log(this.$route.params.cart)
  }

However, when I try to access the data stored in cart, it simply prints ":cart" in the console instead of the actual data. What am I doing wrong?

Answer №1

By replacing

<router-link to="/post/:cart">Check out</router-link>
with
<router-link to="/post/test">Check out</router-link>
, the console will display test. This occurs because using :cart creates a placeholder for the parameter "cart" in the redirect.

If you wish to pass more parameters, you can attempt something similar to

<router-link :to="{ path: '/post/', params: { a: 'a', b: 'b', c: 'c' }}">Check out</router-link>
, but it may be necessary to modify your route.js by removing :cart.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying when a browser is closed with multiple tabs open in Internet Explorer

I need to detect when a browser tab is closed in order to trigger a Struts action. I have successfully implemented this for a single tab using the following JavaScript code: <script type="text/javascript> function loadOut() { if ((window.event.c ...

extracting values from an array using the map function in React

In React JSX, I have an array called levels that may contain arrays with various level names such as one, two, and three. Within my render function, I utilize {renderLevels} to display all levels separated by commas. This approach works well: const rende ...

How can I access an array option that combines both global and target-specific specifications within a grunt plugin?

Currently, I am in the process of creating a grunt plugin that includes options which can consist of arrays of values. These values are specifically file paths (distinct from the files listed in the task's own 'files' property). The setup fo ...

Accepting PHP multidimensional array through ajax

My PHP code includes a script to open a database, fetch data, and encode it into JSON format. include_once($preUrl . "openDatabase.php"); $sql = 'SELECT * FROM dish'; $query = mysqli_query($con,$sql); $nRows = mysqli_num_rows($query); if($nRow ...

Having trouble with material-ui installation in React, Redux, and React-Router project

Guide: https://i.stack.imgur.com/k1UMV.png Due to using redux and react router, incorporating MuiThemeProvider at the top of the chain is a bit challenging. What would be the most effective method to integrate this particular library? This is my ReactDO ...

Serve unique data to different bots and human visitors using express.js and node.js

I am looking for a method to differentiate between bot (such as google or bing) and human incoming requests, in order to provide tailored data to each. This could include serving json data for client-side javascript to build the site or preprocessed html. ...

Using AJAX to submit a single form

Within my HTML view, I have multiple forms that are displayed using a PHP foreach loop. One of the form examples is as follows: <form method="POST" class="like-form-js"> <input type="hidden" name="post_id" value="<?= $post['i ...

Implementing an automatic link generation feature for files within a directory using JavaScript

I could really use some assistance with this. I created a YouTube example, which can be viewed in this PLNKR LINK: http://plnkr.co/edit/44EQKSjP3Gl566wczKL6?p=preview In my folder named embed, I have files titled p9zdCra9gCE and QrMOu4GU3uU, as shown belo ...

How to implement v-tooltip with v-for in Vuetify?

I'm having trouble using the v-tooltip within a v-for loop. It seems like my binding is off, preventing it from showing up correctly. The v-tooltip works fine when used outside of the v-for loop: <div v-for="item in items"> <v-t ...

Communication between a directive controller and a service via an HTTP call

I'm currently developing an Angular directive that loads a Highchart.js area graph by passing some variables to it. Here's how I am using the directive: <andamento-fondo-area-chart color="#3FAE2A" url="../data.json"></andamento-fondo-a ...

strange issue encountered while utilizing JavaScript's async/await syntax

Recently, I encountered an issue while trying to retrieve a random user from the randomuser API using code in my Vue frontend. // Here is the structure of the API response { info: { // details omitted }, results: [ {//random user data} ] } // This snippet ...

Retrieve user-specific relational data

In my Supabase database, I have three main tables: users, teams, and members. The users table stores information about all users who sign up using auth. Here are the details contained in this table: id displayname email 602eff1e-6300-491e-b821-44e ...

Oops! The page you're looking for at /api/tasks

Whenever I try to access: http://localhost:3000/api/tasks, I keep getting a "Cannot GET /api/tasks" error message. This is my server.js: var express = require('express'); var path = require('path'); var bodyParser = require('body ...

Generate a CSV file using Javascript

I am working with an HTML table (table id='testTable') and a button in the HTML code: <button id="btnExport" onclick="javascript:xport.toCSV('testTable');">CSV</button> There is also JavaScript code involved: toCSV: func ...

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Implementing dynamic properties binding in Vue components

Trying to dynamically bind a prop name to a vuetify component using vue 2.x and vuetify 1.5x. The v-tooltip component requires a prop for the tooltip location, such as bottom or right. Normally, you would pass the prop like this: <v-tooltip bottom>& ...

Guide on incorporating dynamic markers into MapBox using Vue/Nuxt

After setting up my MapBox, I wanted to dynamically add markers using Vue/Nuxt. However, the markers are not appearing on the map and I'm unsure of what the issue could be. The code snippet below shows that console.log() prints the correct coordinate ...

What are the steps to achieve consistent response behavior in POSTMAN that matches that of a web browser?

Below is an example of my code: const express = require('express'); const app = express(); app.get('/', function (req, res) { res.setHeader('Content-Type', 'text/html'); res.write("First \n"); set ...

Transforming unknown JSON data into a fresh JSON structure

An undefined JSON object is being returned to a Node.js/Express.js application from a URL API endpoint http://someserver:someport/some_api_url?_var1=1. This particular JSON input always follows the same format and must be transformed into a new JSON object ...

Retrieve the image description using the file_picker_callback and image uploader in Tinymce

TL:DR I am attempting to retrieve the value of the image_description field using JavaScript to include it in my post XHR request Original query: I am utilizing the file_picker_callback type image I have enabled the image_description input field in my ...