Search code examples
vue.jsurlparametersparameter-passinghref

How to include dynamic content in URL parameters vue js


I want to add a parameter to a URL inside a href attribute. I'm using Vue js and those parameters should be dynamic. How can I do this?

<a href="localhost/doctors?{{ dynamic content }}"> 

or

<a href="localhost/doctors?${"dynamic content"}>

not working. Vue gives me an error that I should bind it. but I tried it too. Couldn't make it work. what is the correct way? I'm a newbie to Vue js.


Solution

  • You should use backticks inside the quotes and add data binding on href.

    <a :href="`localhost/doctors/${dynamic_content}`">
    

    In the above, the dynamic_content can be a computed, data, props or any other reactive property.