javascript - vue loop problem
PHPz
PHPz 2017-05-18 11:01:29
0
1
625

Can vue loop through a fixed variable?
For example, if I have num=3
I want to loop num times

<!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>

<p id="app">
    <p v-for="n in full"></p>
    <p v-if="ishalf"></p>
    <p v-for="n in empty"></p>
</p>
<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>


PHPz
PHPz

学习是最好的投资!

reply all(1)
仅有的幸福

<!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>

<p id="app">
    <p v-for="n in full"></p>
    <p v-if="ishalf"></p>
    <p v-for="n in empty"></p>
</p>
<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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template