当前位置:网站首页>v-for指令:根据数据生成列表结构

v-for指令:根据数据生成列表结构

2022-08-10 16:24:00 爱雨天

 

 

 

 

 

 

 

 

<!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>
    <style>
        .active{
            border: 1px solid red;
        }




    </style>




</head>
<body>
    <div id="app">
        <input type="button" value="添加数据" @click="add">
        <input type="button" value="移除数据" @click="remove">

        <ul>
            <li v-for="(it,index) in arr">
                {
   {index+1}}许嘉茵币2:{
   {it}}
            </li>
        </ul>
       <h2  v-for="item in vegetables" v-bind:title="item.name">
            {
   {item.name}}
       </h2>
         
    
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var app=new Vue({
            el:"#app",
            data:{
                arr:["北京","上海","广州","深圳"],
                vegetables:[
                    {name:"徐继业"},
                    {name:"徐锦江"}
                ]
            },
            methods:{
                add:function(){
                    this.vegetables.push({name:"必杀"})
                },
                remove:function(){
                    this.vegetables.shift();
                }
            }
         
            }
        
        )
    </script>
</body>
</html>

原网站

版权声明
本文为[爱雨天]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_52634719/article/details/126162512