定义一个roleForm :undefined 再方法里面添加 //tableData数据样式 //this.tableData={id:1,name:zhangsan},{id:2,name:zhangsan},{id:3,name:zhangsan} const id=2 this.roleForm = this.tableData[ this.tableData.findIndex((role) => role.id === id) ]; console.log('this.roleForm',this.roleForm)
控制台:this.roleForm {id:2,name:zhangsan}