首页 > 技术文章 > vue2.0关于for循环 index的使用方法

shj-com 2017-11-19 22:22 原文

<!DOCTYPE html>
<html>
<head>
    <title>for循环</title>
</head>
<body>
<script type="text/javascript" src="vue2.js"></script>
<script type="text/javascript">
    window.onload=function(){
        new Vue({
            el:"#box",
            data:{
                list:['width','height','border']
            },
            methods:{
                add(){
                    this.list.push("back");
                }
            }
        })
    }
</script>

<div id="box">
    <input type="button" name="" value="添加" @click="add">
    <ul>
        <li v-for="(val,index) in list">
            {{val}} {{index}}
        </li>
    </ul>

</div>
</body>
</html>

 

推荐阅读