vue循环问题

菜lee
  • 731

vue能循环一个固定变量嘛?
比如说我num=3
我要循环num次

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/vue@2.3.3"></script>
</head><body>

<div id="app">
    <div v-for="n in full"></div>
    <div v-if="ishalf"></div>
    <div v-for="n in empty"></div>
</div>
<script>
    const MAXSIZE = 5;
    var vm = new Vue({
        el : '#app',
        props: {
            score:{
                type: Number,
                defualt: 4.5
            }
        },
        data:{
            num : 3
        },
        created(){
            this.full = Math.floor(this.score);
            this.ishalf = this.score!=this.full;
            this.empty = Math.floor(MAXSIZE-this.score);
        }
    })
</script>
</body></html>


回复
阅读 1.7k
1 个回答
caryhgq
  • 3.5k

clipboard.png

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/vue@2.3.3"></script>
</head><body>

<div id="app">
    <div v-for="n in full"></div>
    <div v-if="ishalf"></div>
    <div v-for="n in empty"></div>
</div>
<script>
    const MAXSIZE = 5;
    var vm = new Vue({
        el : '#app',
        props: {
            score:{
                type: Number,
                defualt: 4.5
            }
        },
        data:{
            num : 3
        },
        created(){
            this.full = Math.floor(this.score);
            this.ishalf = this.score!=this.full;
            this.empty = Math.floor(MAXSIZE-this.score);
        }
    })
</script>
</body></html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏