如何在 window.open 事件中插入 vuejs 变量

how to insert vuejs variable in window.open event

在我的代码中

<tr v-for="person, index in People" :key='index'>
<td>
<button type="button" onclick="window.open('/details/'+person.id,'_blank')">
details</button>
</td></tr>`

'People' 是脚本中定义的 json 数据。我如何使用 v-for 函数定义的 'person.id' 变量为新的 window 创建 url?

希望以下内容对您有用。

HTML

<div v-for="person, index in people" :key="index">
   <button v-on:click="onButtonClick(person.id)">Detail</button>
</div>

JS

new Vue({
    data: {
        people: [{ id: 0 }, { id: 1 }, { id: 2 }]
    },
    methods: {
        onButtonClick: function (id) {
            window.open(`/details/${id}`, '_blank')
        }
    }
});