v-for示例二

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <li v-for="(book,index) in books" >{{index}}--{{book.name}}</li>
// 遍历对象属性时,有两个可选参数,分别是键名和索引:
        <p v-for="(value,key,index) in userInfo">{{index}}--{{key}}--{{value}}</p>
    </div>
    <script>
        var v=new Vue({
            el:"#app",
            data:{
                books:[{'name':'java编程思想'},{'name':'java设计模式'}],
                userInfo:{
                    'name':'zhangsan',
                    'age':28
                }
            }
        });
    </script>
</body>
</html>
posted @ 2020-05-08 22:17  玄空2  阅读(136)  评论(0编辑  收藏  举报