vue中v-for数组和对象的循环

vue中v-for数组和对象的循环

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <ol>
            <li v-for="item,index in todos" :key="index">
                {{ item.text }}-{{index}}
            </li>
        </ol>
        <ul>
            <li v-for="value,key in object" :key="key">
                {{key}}:{{ value }}
            </li>
        </ul>
    </div>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                todos: [{
                        text: '学习 JavaScript'
                    },
                    {
                        text: '学习 Vue'
                    },
                    {
                        text: '整个牛项目'
                    }
                ],
                object:{
                    title:"how to do lists in vue",
                    author:'ada',
                    publishedAt:'2021-07-04'
                }
            }
        })
    </script>

</body>

</html>

 

效果:

 

posted @ 2021-07-04 13:13  前端HL  阅读(734)  评论(0编辑  收藏  举报