【发布时间】:2021-04-22 11:56:14
【问题描述】:
我这样写代码:
<select class="section" @change="showIndex($event.target.selectedIndex)">
<option v-for="number in 50">{{ number}} per page</option>
</select>
<div class="product__layout" v-for="product in showItem">
<p class="product__name">{{ product.name }}</p>
...
data() {
return {
products:[
{ name: 'abc' },
{ name: 'xyz' },
],
}
},
methods:{
showIndex(selectedItem){
return selectedItem
}
},
computed:{
showItem(){
return this.products.slice(0, this.showItem)
}
}
我的代码没有结果。有人可以帮我解决我做错了什么吗?
【问题讨论】:
-
不使用 watch 函数的返回值。这看起来作为计算属性会更好
-
@Phil 我试过用计算但它也没有结果
-
您的命名似乎有些不一致。是
showItem还是showIndex,这个价值从何而来? -
请edit your question包含代码
-
@phil 好的,我编辑了它