Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue: on div click, go to url defined in data

Tags:

vue.js

I have this kind of objects in an array:

{
  name: 'name1',
  url: 'http://url-1.tld'
},
{
  name: 'name2',
  url: 'http://url-2.tld'
}

On div click, I want to to a window.location.href to the url, but I can't seem to get the url from the data to my method.

<div v-for="person in persons" v-on:click="select($event)"></div>

select: function(event) {
  window.location.href( ??? )
}

Anybody have suggestions?

like image 880
Filip Blaauw Avatar asked Oct 24 '25 00:10

Filip Blaauw


1 Answers

You need to pass the person as the argument to select, not $event:

<div v-for="person in persons" v-on:click="select(person)"></div>

select: function(person) {
  window.location.href = person.url;
}
like image 177
thanksd Avatar answered Oct 25 '25 22:10

thanksd