美文网首页
Vue列表渲染

Vue列表渲染

作者: 九瀺 | 来源:发表于2019-09-29 02:33 被阅读0次
<ul>
    <li v-for = "(item,index) in persons" :key = ""index></li>
</ul>

<button @click = "delete(index)">删除</button>
<button @click = "update(index,{name : "sss", age : 52})">更新</button>
...

data : {
    persons : [  {name : "cat",age : 18},
            {name : "cat",age : 18},
            {name : "cat",age : 18}
                    ]
}
methods :{
        delete(index) {
            this.persons.splice(index,1);
                },
        updata(index,newVal) {
            this.persons.splice(index,1,newVal)
                }
}
vue本身只是监视了persons的改变,没有监视数组内部数据的改变
vue重写了数组中的一系列改变数组内部结构的方法(先调用原生,在更新界面),类似splice、push等等

splice方法具有增删改的作用 splice(index,howmany,value1,value2...) index 为修改起始位置的索引,howmany为修改长度(为0则是增加),value为需要替换的值(可以为多个)

相关文章

  • vue列表渲染

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

  • 2019-03-09 Vue基础知识

    Vue2.x 模板语法,条件渲染,列表渲染渲染 Vue2.x Router,Vuex 集成Vue2.x Vue2....

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

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

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

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

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

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

  • VUE列表渲染

    我们用 v-for 指令根据一组数组的选项列表进行渲染。v-for 指令需要使用 item in items 形式...

  • Vue 列表渲染

    Vue 使用 v-for 指令渲染一组数据 渲染数组 渲染对象 在 v-for 指令中可以使用 of 分隔符替换 ...

  • Vue 列表渲染

    列表显示数组: v-for / index对象: v-for / key 列表的更新显示删除item替换item

  • vue列表渲染

    最近碰到一个vue列表渲染的问题 通过ajax获取到的数据然后赋给data里面的数组,发现页面上居然没显示 刚开始...

  • Vue列表渲染

    splice方法具有增删改的作用 splice(index,howmany,value1,value2......

网友评论

      本文标题:Vue列表渲染

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