I have a Vue application, I am specifying all links in my data element like:
data(){
return{
products:[
{
Name: "Product 1",
buy_now_link: "https://www.product_1.com/",
},
{
Name: "Product 2",
buy_now_link: "https://www.product_2.com/",
}
]
}
}
The urls above might not always have a pattern, they could be different.
In my template, I have a button that should redirect the user to the links provided in the specified urls. The template code is below:
<div class="content">
<div class="nested" v-for="product in products">
<div class="one">
<button class="buy_now_button" :click="window.location='buy_now_link'">Buy now</button>
</div>
</div>
</div>
I get an error Cannot set property 'location' of undefined
How can I solve this?
:click="window.location='buy_now_link'"by@click="window.location=product .buy_now_link". The colon is used to set a prop, the@is used to add an event listener.