iview tree 树形控件 单选

	
      treeData:[
      {
      title:"总分类",
      		id:'0',
      		expand: true,
      		checked:false,
      		children:[
      		{
      		title:'分类1',
      		id:'1',
      		checked:false,
      		children:[
      		{
      		title:'分类101',
      		id:'101',
      		checked:false,
      		]
      		},
      		{
      		title:'分类2',
      		id:'2',
      		checked:false,
      		},
      		]       	
      }
      			
      ]

选中默认值
// tree 树数据
//ids 要选中节点的id
filterDeviceTree(tree, ids) {
tree.forEach(item=>{
if(ids==item.id){
item.checked = true
}
else{
item.children = this.filterDeviceTree(item.children, ids)
}
})
return tree;
},

treeChange(arr, obj) {     

  arr.forEach((item) => { 
    item.checked = false;
  });
  // 只选中最后一次选中的
  if(arr.length==0){//再次点击取消选中

    obj.checked=false
    this.selectedCode ="";
    this.selectedName = "obj.title";
  }else{
    obj.checked = true;
    this.selectedCode = obj.id;
    this.selectedName = obj.title;
  }
  
 
 
},

你可能感兴趣的:(vue.js)