gpt4 book ai didi

javascript - Vue.js:如何读取计算函数中的 $index ?

转载 作者:行者123 更新时间:2023-11-28 18:27:26 25 4
gpt4 key购买 nike

我有链接列表:

  <ul id="menu">
<li v-for="item in items">
<a href v-bind:href=link>{{item.message}}</a>
</li>
</ul>


var example1 = new Vue({
el: '#menu',
data: {
items: [
{ message: 'Link1' },
{ message: 'Link2' }
]
},
computed: {
link: function() {
return f($index) // how do I access current array index ??
}
}
})

我可以通过在 href 属性中使用 Mustache 标记来实现所需的结果,但必须可以从计算函数内访问此 $index 变量?

最佳答案

不能

这就是方法的用途:

<a href v-bind:href="link($index)">{{item.message}}</a>

methods: {
link: function(index) {
return f(index)
}
}

关于javascript - Vue.js:如何读取计算函数中的 $index ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com