Using Vue JS to dynamically add a variable to the end of a URL

Using the v-for method on my page, I am displaying a series of numbers.

1234
122356
124
12312

Each number is outputted using v-for and I need to attach them to a link structure like this:

<a href="/order/1234">1234</a>
<a href="/order/122356">122356</a>
<a href="/order/124">124</a>
<a href="/order/12312">12312</a>

Currently, I am getting:

<a href="/order/{{ order.number }}">1234</a>
<a href="/order/{{ order.number }}">122356</a>
<a href="/order/{{ order.number }}">124</a>
<a href="/order/{{ order.number }}">12312</a>

I'm confused about what's going wrong. Can someone point out my mistake?

Answer №1

To handle this scenario, it is recommended to utilize the v-bind directive as shown below:

<a v-bind:href="'/order/' + order.number">1234</a>
<a v-bind:href="'/order/' + order.number">122356</a>
<a v-bind:href="'/order/' + order.number">124</a>
<a v-bind:href="'/order/' + order.number">12312</a>

In a similar manner, you can achieve the same result with the concise syntax:

<a :href="'/order/' + order.number">1234</a>
<a :href="'/order/' + order.number">122356</a>
<a :href="'/order/' + order.number">124</a>
<a :href="'/order/' + order.number">12312</a>

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

Problems encountered with the functionality of Sidr when using an AngularJS button with ng

Utilizing the Sidr mobile menu alongside AngularJS has been a breeze so far. However, I encountered an issue when trying to include a search bar within the mobile navigation - the button functionality seems to be affected. Interestingly, when I placed the ...

Having issues with setting up nodejs on kali linux

Whenever I try to execute the configure script ./configure for nodejs installation, it fails to run successfully. Traceback (most recent call last): File "./configure", line 19, in <module> from distutils.spawn import find_executable ModuleN ...

JQuery is used to create a pop-up box

As a newcomer to JQuery, I am working on implementing a pop-up box on my webpage. Utilizing a jQuery plugin derived from Ray Stone's leanModal: (function($) { $.fn.extend({ leanModal: function(options) { var defaults = { top: 10 ...

Monitor the scrolling progress across four separate HTML pages without the percentage decreasing when scrolling back up

I am in the process of developing an e-learning platform and I would like to include a scrolling indicator that visually represents the progress of pages read. The website consists of four HTML pages, with each page corresponding to 25% of the scroll bar. ...

Tips for deleting a button from a DataTable file upload feature

I currently have Datatable set up to upload images using the code snippet below: { label: "Images:", name: "files[].id", type: "uploadMany", display: function ( fileId, counter ) { re ...

A guide on adjusting a function to pause execution until a line is complete

In the code snippet below, there is an angularJS function named myFunc: $scope.myFunc = () => { myModule.getConfig().update(params); myModule.go(); myModule.log('ok'); }; Additionally, there is a go function defi ...

AJAX's PUT method encountering issues in Google Chrome

I have successfully implemented this in Mozilla and IE, but for some unknown reason, it is not working on Chrome. In Chrome, the error callback is triggered every time with an error code of zero. Numerous posts on Stackoverflow keep mentioning how all majo ...

Retaining the data retrieved from a successful $.ajax call's done() function

After successfully retrieving the desired information in the done method, I encountered an issue when trying to assign it to a variable with broader scope. This approach had worked fine with $.each(...), leading me to assume that it would work here too. v ...

Adding an object to an ArrayList: A step-by-step guide

I'm encountering issues with adding objects to the list. I have a list of floors, each floor containing rooms. I can successfully add a floor, but I'm unsure how to add rooms to the floor list. I've attempted to access floor[index] or id, b ...

Automatically adjust zoom on focused object within a D3 force layout

I have implemented an autocomplete feature in my force directed graph to highlight selected nodes by coloring them red. Now, I am looking to implement a "zoom" functionality where the window magnifies to 400% the size of the selected node and centers it wi ...

Obtaining a key from a Firebase query using JavaScript

Is there a way to retrieve the key where UID is equal to: firebase.auth().currentUser.uid? I need to be able to update this information whenever the user inputs new data. Also, how can I update the information effectively? I have tried using orderByChild ...

Codepen is experiencing difficulties loading textures in three.js

Recently, I've delved into learning three.js using codepen.io. However, I encountered an issue while attempting to add a texture to my box geometry - the texture just won't show up. Can anyone help me troubleshoot this problem in my code? const c ...

Preventing flexbox containers from being affected by overflow elements

I am looking to implement overflow: scroll within a flexbox layout. I am unsure of how to link an image directly from my Google Drive, so I have provided the URL instead: https://drive.google.com/open?id=17uM5twoprxmbo5xQ37kgeTaMwn7FGSu_ When using the o ...

Implementing html5mode in Express.js and Angular.js for cleaner URLs

I've been working on resolving the issue of avoiding # in my Angular app with an ExpressJS server-side setup. I found a solution to enable html5mode and it worked well. However, whenever there is another 'get' request to fetch data from a di ...

Updating content with Ajax in Laravel

Hey, I'm currently facing an issue with my update functionality. Below is the blade code snippet: <div class="form-group floating-label" id="role_colaboration1"> <select name="{{$role}}[]" id="role" class="form-control"> ...

Is it possible to use ng-click to pass multiple arrays at once?

I am working with a nested JSON object array and successfully displaying Inner Items grouped by Info in HTML using ng-repeat. Each Inner Item has a checkbox with an ng-click event handler that passes the selected Inner Items to the controller. However, I n ...

Exploring the usage of multidimensional arrays in React components

How can I extract data such as teamId from the "teams" array using datas.map() method in a multidimensional array? Any tips or help would be appreciated. Is there another way to map out this data? { "gameId": 3226262256, "platformId": "NA1", " ...

What steps can you take to prevent a potential crash from occurring when an unauthorized user attempts to access a page without logging in?

I've encountered an issue where the app crashes when trying to access a page that requires logging in. The reason for this crash is because the page attempts to load undefined data, resulting in the error: TypeError: Cannot read property 'firstN ...

Get the desired text following the second <br> tag using jQuery

I am trying to identify a specific string that comes after the second occurrence of <br> tag and then check if this string contains any numbers. If there are no numbers present, I want an alert to be shown. The code for performing this action is func ...

The method for viewing stack traces in Express JS server logs

In my tech stack, I'm utilizing Nuxt (Vue), Express.js, and Axios. Encountering a scenario where a REST call fails, exemplified by the code snippet below: axios.get('api/data-test'); The client displays an error message like this: xhr.js ...