美文网首页Vue
vue中的列表(数组)渲染例子

vue中的列表(数组)渲染例子

作者: 程序员同行者 | 来源:发表于2018-07-10 11:16 被阅读1次

vue中的列表(数组)渲染例子

<!DOCTYPE html>
<html>
<head>
    <title>vue中的列表渲染</title>
    <script src="./vue.js"></script>

</head>
<body>
    <!-- // 循环数组 -->
    
    <div id="app">
        <!-- 1. -->
    <!--    <div v-for="(item,index) of list"
             :key="item.id">
            {{item.text}}----{{index}}
        </div> -->

        <!-- 2. //使用模板占位符<template></template> -->
        <template v-for="(item, index) of list"
                  >
        <div>
            {{ item.text }} ---- {{ index }}
        </div>
        <span>
            {{ item.text }}
        </span>
    </template>
    </div>
    
    <!-- // 循环对象 -->
    <div id='app-1'>
        <div v-for="(item, key, index) of userInfo"
             :key="item.index">
        {{item}} --- {{key}}----{{index}}
    </div>
    </div>
    
<script>
    //数组操作方法 push  pop shift unshift splice sort reverse
    // 修改数组的内容并响应式显示有三种方法
        //1. set方法,(全局set,实例set)
            // Vue.set(vm.list,1,{id:'11',text:'pwd'})
            // vm.$set(vm.list,1,{id:'11',text:'pwd')
        //2. 直接改数组引用
            // // vm.list = {
            //      id: '1',
            //      text: 'hello'
            //  },
            //  {
            //      id: '2',
            //      text: 'world'
            //  },
            //  {
            //      id: '3',
            //      text: 'dell'
            //  }
        //3. 调用数组的变异方法如splice
            // vm.list.splice(0,0,{id:'1',text:'hello111'})
    var vm =  new Vue({
        el: '#app',
        data: {
            list: [
            {
                id: '1',
                text: 'hello'
            },
            {
                id: '2',
                text: 'world'
            },
            {
                id: '3',
                text: 'dell'
            }
                

        ]
    }
        
    
    }) 

    //修改对象内容并响应式显示有两种方法
    //1. 直接修改对象引用
        // vm1.userInfo = {name: "Dell",age: "28",gender: "male",salary: "secret",address:"beijing"}

    //2. set方法,(全局set,实例set)
            // Vue.set(vm1.userInfo,"address", "Dell111")
            // vm1.$set(vm1.userInfo,"address", "Dell111")
    var vm1 =  new Vue({
        el: '#app-1',
        data: {
            userInfo: {
                name: "Dell",
                age: "28",
                gender: "male",
                salary: "secret"
            }
        
    }
        
    })
    
</script>
</body>
</html>

相关文章

  • vue中的列表(数组)渲染例子

    vue中的列表(数组)渲染例子

  • vue列表渲染

    vue列表渲染v-for类似js语言中的for循环,用vue列表渲染指令渲染数组,可以类比js中用for循环遍历数...

  • 2018-09-11

    Vue中的for循环 v-for 指令可以绑定数组的数据来渲染一个项目列表: 链接Vue.js 输入的Vue.js...

  • vue中的条件渲染例子

    vue中的条件渲染例子

  • 6.vue中的条件渲染&列表渲染

    1.vue中的条件渲染 2.vue中的列表渲染&dom循环 3.对象循环

  • uniapp之列表渲染中key值的作用(vue.js)

    参考:Vue列表渲染(1) 列表渲染示例 (2) :key 值的选取 使用 v-for 循环 array 中 it...

  • vue项目-数组处理

    在vue项目实战 显示|隐藏 查询返回数组 过滤数组 数组去重 渲染列表 思路总结:在没有掌握全部技术的前提下怎么...

  • v-for

    接下来的内容主要出自vue的官方文档 渲染列表 我们可以用 v-for 指令基于一个数组来渲染一个列表。v-for...

  • Vue 循环渲染

    v-for指令的使用 在 Vue 中,可以使用 v-for 指令绑定数据到数组来渲染一个列表。 使用 v-for ...

  • 6、列表渲染

    title: 6、列表渲染date: 2017-08-1 18:38:20tags: vue笔记(妙味) 遍历数组...

网友评论

    本文标题:vue中的列表(数组)渲染例子

    本文链接:https://www.haomeiwen.com/subject/abizuftx.html