2022-10-19 11:01阅读: 68评论: 0推荐: 0

列表渲染(循环指令)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <h2>v-for 指令</h2>
    <!--        -可以循环:数组   v-for="(url,index) in urls"      位置不能换-->
    <!--        -可以循环:对象   v-for="(value,key) in obj"       如果只接收一个值,这个值就是value-->
    <!--        -可也循环:数字   v-for="i in num"       从1开始,循环到数字的个数-->
    <ul>
        <Li v-for="(img,index) in imgList" @click="clickEvent">
            <p>{{index}}</p>
            <img :src="img" alt="">
        </Li>
    </ul>
    <ul>
        <li v-for="(value,key) in obj">{{key}}:{{value}}</li>
    </ul>
    <p v-for="i in num">{{i}}</p>
</div>
</body>
<script>
    const app = Vue.createApp(
        {
            data() {
                return {
                    imgList: ['https://www4.bing.com//th?id=OHR.BridalVeilFalls_ZH-CN3954641670_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp&w=240&h=135', 'https://www4.bing.com//th?id=OHR.GlassOctopus_ZH-CN6853414529_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp&w=240&h=135'],
                    obj: {
                        name: 'szw',
                        age: 12
                    },
                    num:100
                }
            },
            methods: {
            }
        }
    )
    app.mount("#app")
</script>
</html>

本文作者:Sherwin

本文链接:https://www.cnblogs.com/sherwin1995/p/16805504.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Sherwin_szw  阅读(68)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.