vue中使用Object.assign导致视图不响应


可以正常响应的

<template>
    <div>
       <ul>
           <li class="li-item" v-for="(item,index) in list" :key="index" @click="hander(item)">
               {{item}}
           </li>
       </ul>
    </div>
</template>
<script>
   export default {
        data(){
            return{
                list:[]
            }
        },
        created(){
            setTimeout(()=>{
                let  arr=[
                    { name:'张三1',flag:true},
                    { name:'张三2',flag:true},
                    { name:'张三3',flag:true},
                    { name:'张三4',flag:true},
                ]
                let newList=[];
                for(let i=0;i<arr.length;i++){
                    let item=arr[i];
                    console.log(item)
                    let a=Object.assign(item,{'select':true});
                    newList.push(a)
                }   
                this.list=newList;
            },300)
        },
        methods:{
            hander(mess){
               for(let i=0;i<this.list.length;i++){
                    if(mess.name==this.list[i].name){
                       this.list[i].select=! mess.select;
                    }
               }
            },
        },
    }
</script>
<style scoped>
.li-item{
    height: 40px;
    background: #c0c0cc;
    line-height: 40px;
    margin-bottom: 10px;
}
</style>

不会正常的响应

今天太晚了,明天我在写一写;休息一会


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM