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>
标签:Vue,obj,CategorID,Country,绑定,code,Key,大佬,Categorise 来源: https://www.cnblogs.com/zyzlb/p/15913220.html