当我将{{num_bottom}}更改为5时,此代码可以正常工作,但我更喜欢使用变量。您能否建议它不正确的原因以及如何修复它?我使用的是Vue 3。
<template>
<tr class="row" v-for="rowIdx in Math.ceil(items.length / {{num_bottom}})">
</template>
<script setup>
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let num_bottom = 5
</script>
如果我将{{num_bottom}}更改为数字(如3),它会起作用。我希望使用变量,这样我就可以在一个位置更改它,并且它会影响所有内容。
1条答案
按热度按时间guicsvcw1#
按照您的写法,
num_bottom
被视为字符串而不是变量。为了修正你的错误,删除
num_bottom
周围的花括号。确保num_bottom
在templates作用域内,你可以通过在setup
函数中声明它来做到这一点。