Vue:点击div,转到数据中定义的url

Fil*_*auw 1 vue.js

我在数组中有这种对象:

{
  name: 'name1',
  url: 'http://url-1.tld'
},
{
  name: 'name2',
  url: 'http://url-2.tld'
}
Run Code Online (Sandbox Code Playgroud)

在div上单击,我想要一个window.location.href来url,但我似乎无法从数据中获取url到我的方法.

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

select: function(event) {
  window.location.href( ??? )
}
Run Code Online (Sandbox Code Playgroud)

有人有建议吗?

tha*_*ksd 6

你需要传递person参数select,而不是$event:

<div v-for="person in persons" v-on:click="select(person)"></div>
Run Code Online (Sandbox Code Playgroud)

select: function(person) {
  window.location.href = person.url;
}
Run Code Online (Sandbox Code Playgroud)