Vue动态绑定Key值


HTML片段

<template>
    <div>
       vue动态添加对象Key值和value值
    </div>
</template>

script片段

<script>
    export default {
        data(){
            return{
              // 假数据  可以是接口返回的数据
                ImV:[
                    {Categorise:'假数据1',CategorID:'1',code:'100',Country:'大佬真棒'},
                    {Categorise:'假数据2',CategorID:'2',code:'200',Country:'大佬很棒'},
                    {Categorise:'假数据3',CategorID:'3',code:'300',Country:'大佬超棒'},
                    {Categorise:'假数据4',CategorID:'4',code:'400',Country:'大佬忒棒'},
                ],
            }
        },
        mounted(){
            this.MyRender()
        },
        methods:{
          // 只用到了里面其中两个数据
            MyRender(){
                let obj={}
                this.ImV.forEach((v,)=>{
                  obj[v.CategorID]=v.Country
                })
                console.log(obj) //打印结果{1: '大佬真棒', 2: '大佬很棒', 3: '大佬超棒', 4: '大佬忒棒'}
            }
        }
    }
</script>

 


免责声明!

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



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