Fork me on GitHub

v-for

<body>
    <div id="app">
        <h1>{{msg2}}</h1>
        <ul>
            <li v-for="(item, index) in music" :key="index">{{item}}</li>
        </ul>

        <h1>{{msg}}</h1>
        <ul>
            <li v-for="(item, index) in food" :key="index">午餐:{{item.name}} 价格{{item.price}}</li>
        </ul>
        </ul>
    </div>
</body>

</html>
<script src="node_modules/vue/dist/vue.js"></script>
<script>
    let vue = new Vue({
        el: app,
        data() {
            return {
                msg: "网红餐厅",
                msg2: "音乐",
                music: [
                    "七里香",
                    "稻香",
                    "晴天",
                    "夜曲"
                ],
                food: [
                    {
                        name: "宫保鸡丁",
                        price: 20
                    },
                    {
                        name: "鱼香肉丝",
                        price: 30
                    },
                    {
                        name: "红烧肉",
                        price: 40
                    }
                ]
            }
        },
        methods: {
            click() {
                console.log(1)
            }
        }
    })
</script>
posted @ 2025-03-26 14:54  一名狗书匠&  阅读(9)  评论(0)    收藏  举报

asd