Creating a link using curly braces {{ }} in VUE js

I need assistance in creating links to different pages using data in curly brackets {{ }}, I am having trouble figuring out the correct way to implement them.

  <div id="app">
      <div v-for="data in categorie">
        <button v-on:click=" filterFunction(data) ">{{data}}</button>
        <a href="testsite{{data}}.html"> test links </a>
      </div>
    </div>

If anyone could provide some guidance, I would greatly appreciate it.

Answer №1

With Vue, you have the ability to bind the href attribute.

<div id="app">
      <div v-for="data in categorie">
        <button v-on:click=" filterFunction(data) ">{{data}}</button>
        <a :href="'testsite' + data + '.html'"> test links </a>
      </div>
    </div>

It's important to be aware of security concerns and ensure that you properly sanitize the data variable on your own.

Answer №2

When working with Vue.js, you can avoid using curly braces and instead utilize the v-bind directive like so:

<div id="app">
      <div v-for="item in categories">
        <button v-on:click="filterFunction(item)">{{ item }}</button>
        <a v-bind:href="'testsite'+ item +'.html'"> test links </a>
      </div>
    </div>

By utilizing v-bind, you can easily insert dynamic data into your URL by placing them within single quotes and adding the variable where necessary.

You can check out this example on JSFiddle.

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

Dealing with Vue Route on Page Reload using MVC Controller

I'm currently facing a problem with my VUE SPA, which is rendered from index.cshtml. Whenever users try to reload the page, it leads them to a 404 error page. How can I manage Vue routes within my MVC application? ...

Modify/Enclose a method within a prototype

I have developed a framework that incorporates function wrapping to create a debugging tool. My current goal is to gather and report information upon the invocation of functions. Here is the initial code snippet I am working with: function wrap(label, cb) ...

The number range filter in ng-table is malfunctioning

what I am trying to accomplish My goal is to create a column that can accommodate two numbers in order to filter numeric data within a specific range for that column. While sorting, pagination, and filtering by 'contain text' are working correct ...

Effective steps after Ajax request

Whenever a user clicks the "like" button, I perform a check in the database to see if they have already liked the photo. This check is done using ajax. If the photo has already been liked, the success message will indicate "already liked", otherwise it wi ...

Verifying in PHP if the request is intended for a JavaScript worker

After doing my research on MDN for the referrer-policy, as well as searching through Google, DuckDuckGo and Stack Overflow, I still find myself stuck on a seemingly simple yet elusive issue. Journey of Data the browser sends a request to the server the ...

Re-enable the jQuery-ui sortable feature after it has been turned off

Here is a snippet of my jQuery code: var status = true; $('#edit').click(function () { if (status) { $('table tbody').sortable({ axis: 'y', update: function (event, ui) { va ...

Tips for updating the class of a button upon clicking it

I have a dilemma with my two buttons - one is green and the other has no background. I want them to change appearance when clicked, from green to one with a dashed border-bottom style. Below is the HTML code for these buttons: <div class="btns"> ...

Exploring the boundaries of HTML data manipulation using JavaScript or jQuery

In my HTML (within a Twig template), there is the following code snippet: <li id="{{folder.id}}" data-jstree='{"icon":"glyphicon glyphicon-tags", "type":"folder"}' ><a href="#">{{folder.name}}</a> I'm attempting to extrac ...

Function that contains a JavaScript reference and observation

I'm experiencing issues with the code below and I'm having trouble figuring out what's causing the problem. function some(){ for (var i=0;i<....;i++) { var oneObject; ...some logic where this object is set oneObject.watch(prop ...

Experiencing excessive CPU utilization from Node.js while executing the vue-cli-service serve command

Whenever I run my npm script that uses vue-cli-service serve, the CPU usage by Node exceeds 100%. How can I troubleshoot this problem? I am using a Mac and have installed Node through nvm. My Node version is 10.16 and my npm version is 6.9. ...

Invoke a controller in Prestashop by utilizing AJAX technology

I am struggling to figure out how to call the method / function in my controller. The controller is named TestController.php, and I also have files named Test.tpl and Test.js. Additionally, I am unsure of what to put in the URL field. My goal is to retrie ...

Can I switch between different accounts on Auth0?

While utilizing next-auth for user sign-ins, I've noticed that there isn't a clearly visible option to switch accounts after signing in. Additionally, if users enter incorrect credentials, there doesn't seem to be a way to sign in with a dif ...

Flashing images with jQuery Flickrush - Encasing the image within <li> tags

I have a div with an unordered list inside: <div id="flickr"> <ul></ul> </div> Currently, I am utilizing a plugin found at this link. To make it functional, I've included the following Javascript code: $(function() { $( ...

javascript date.js parsing and sorting an array of objects

I'm currently working on creating a JavaScript array of objects, utilizing date.js to parse dates, and then sorting that array using date.js compare methods. Below is a snippet of code that highlights the two issues I am facing. Issue 1: How can I ha ...

Disregarding 'zIndex' directive within JavaScript function, an image stands apart

There is an issue with the z-index values of rows of images on my webpage. Normally, the z-index values increase as you scroll further down the page. However, I want certain items to have a lower z-index than the rest (except on hover). These items are i ...

Investigating High Energy Usage on Vue.js Websites: Identifying the Root Causes

My Vue.js application has grown to be quite large with over 80 .vue components. Users have been complaining about their phone batteries draining quickly and Safari displaying a "This webpage is using significant energy..." warning. I have tried investigat ...

Error encountered with NodeJS Express Module: TypeError - Unable to access property 'finished' as it is undefined

Recently, I've been working on creating an API that can extract text from a website based on specific keywords. To achieve this, I utilized Selenium to load the site and retrieve the text. However, I encountered an issue with sending the extracted tex ...

Adding a specific element to an array using JQuery

I am in the process of developing a web application using jQuery to track goals and habits. Users can set a main goal such as 'Discipline' and then add sub-goals or habits related to that main goal (e.g. 'exercise every day'). Organizi ...

Exploring the Power of Ajax Integration with Mongodb

I have been trying to figure this out for a while now, but I'm lost. I am attempting to use Ajax to retrieve information from a collection named 'reizen' in MongoDB. My goal is to cycle through all elements within the collection and extract ...

The custom validation process encountered an error: callback is not a valid function

Encountering an issue with a custom validator in node.js while using mongoose. The goal is to verify if a query already exists in the headerLog before attempting to insert it. Take a look at the code snippet below: var mongoose = require('mongoose& ...