zoukankan      html  css  js  c++  java
  • Vue之for循环

    Vue中for循环的用法总结如下:

    1.基本用法 v-for

    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  
        <style>  
      
        </style>  
        <script src="vue.js"></script>  
        <script>  
            window.onload=function(){  
                new Vue({  
                    el:'#box',  
                    data:{  
                        arr:['apple','banana','orange','pear']  
                    }  
                });  
            };  
        </script>  
    </head>  
    <body>  
        <div id="box">  
            <ul>  
                <li v-for="value in arr">  
                    {{value}}  
                </li>  
            </ul>  
        </div>  
    </body>  
    </html>  

    结果:

    2.带索引的用法

    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  
        <style>  
      
        </style>  
        <script src="vue.js"></script>  
        <script>  
            window.onload=function(){  
                new Vue({  
                    el:'#box',  
                    data:{  
                        arr:['apple','banana','orange','pear']  
                    }  
                });  
            };  
        </script>  
    </head>  
    <body>  
        <div id="box">  
            <ul>  
                <li v-for="value in arr">  
                    {{value}}   {{$index}}  
                </li>  
            </ul>  
        </div>  
    </body>  
    </html>  

    描述:

    使用{{$index}}可以提供索引

    结果:

    3.使用(k,y) in arr

    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  
        <style>  
      
        </style>  
        <script src="vue.js"></script>  
        <script>  
            window.onload=function(){  
                new Vue({  
                    el:'#box',  
                    data:{  
                        arr:['apple','banana','orange','pear'],  
                        json:{a:'apple',b:'banana',c:'orange'}  
                    }  
                });  
            };  
        </script>  
    </head>  
    <body>  
        <div id="box">  
            <ul>  
                <li v-for="value in arr">  
                    {{value}}   {{$index}}  
                </li>  
            </ul>  
            <hr>  
            <ul>  
                <li v-for="value in json">  
                    {{value}}   {{$index}}  {{$key}}  
                </li>  
            </ul>  
      
            <hr>  
            <ul>  
                <li v-for="(k,v) in json">  
                    {{k}}   {{v}}   {{$index}}  {{$key}}  
                </li>  
            </ul>  
        </div>  
    </body>  
    </html>  

    描述:

    {{k,v}} in arr         k代表key,  v代表value

    结果:

  • 相关阅读:
    在sql语句中使用 xml for path 格式化字符串的方法总结
    Android handler的使用简单示例
    easyui datagrid中 多表头方法总结
    使用ICSharpCode.SharpZipLib.Zip类库解压zip文件的方法
    ThreadPoolExecutor 优雅关闭线程池的原理.md
    ThreadPoolExecutor 几个疑惑与解答
    如何在运行时(Runtime)获得泛型的真正类型
    为什么 EXISTS(NOT EXIST) 与 JOIN(LEFT JOIN) 的性能会比 IN(NOT IN) 好
    Spring MVC 上下文(ApplicationContext)初始化入口
    Tomcat生成的session持久化到MySQL
  • 原文地址:https://www.cnblogs.com/chaofei/p/7706707.html
Copyright © 2011-2022 走看看