suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Javascript – Vue-Loop-Problem

Kann Vue eine Schleife über eine feste Variable durchführen?
Zum Beispiel, wenn meine Nummer = 3 ist
Ich möchte eine Anzahl von Malen wiederholen

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


PHPzPHPz2817 Tage vor698

Antworte allen(1)Ich werde antworten

  • 仅有的幸福

    仅有的幸福2017-05-18 11:03:29

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

    Antwort
    0
  • StornierenAntwort