[vue basics] Basic use of 09 v-for

1. Basic usage examples 

 Example:

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

<head>
    <script type="text/javascript" src="../js/vue.js"></script>
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title></title>
</head>

<body>
    <div id="root">
        <span v-for="i in loopNum">{
   
   {i}}</span><br>
        <span v-for="char in testString">{
   
   {char}}</span><br>
        <span v-for="element in testArr">{
   
   {element}}</span><br>
        <ul>
            <li v-for="item in testObject">{
   
   {item}}</li>
        </ul>
    </div>

    <script>
        new Vue({
            el: '#root',
            data: {
                loopNum: 10,
                testString: "abc",
                testArr: ["a", "b", "c"],
                testObject: {
                    k1: "value1",
                    k2: "value2"
                }
            },

        })
    </script>
</body>

</html>

Two, use the index

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

<head>
    <script type="text/javascript" src="../js/vue.js"></script>
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title></title>
</head>

<body>
    <div id="root">
        <div v-for="(item, index) in testArr">
            {
   
   {index}} -- {
   
   {item}}
        </div>
        <div v-for="(value, key, index) in testObject">
            {
   
   {index}} -- {
   
   {key}} -- {
   
   {value}}
        </div>
    </div>

    <script>
        new Vue({
            el: '#root',
            data: {
                testArr: ["a", "b", "c"],
                testObject: {
                    k1: "value1",
                    k2: "value2"
                }
            },

        })
    </script>
</body>

</html>

Guess you like

Origin blog.csdn.net/ChaoChao66666/article/details/130718141