vue 键值相同直接使用值

(function (window) {
    'use strict';
    const vm = new Vue ({
        el:'#app',
        data:{
            name:'',
            list:[
                {id:1,name:'抽烟',completed:false},
                {id:2,name:'喝酒',completed:true},
                {id:3,name:'烫头',completed:false},
            ]
        },
        methods:{
            add(){
                if(this.name.trim() === ''){
                    return
                }

                const id=this.name[this.name.length - 1].id+1

                this.list.push({id,name:this.name,completed:false})

                this.name=''

            
            }
        },
    })

})(window);
posted @ 2019-06-10 11:02  一只大鹅  阅读(433)  评论(0编辑  收藏  举报