需求是 在新建任務的時候,選中tree組件中的某條數據,在編輯這個任務的時候,通過后台的數據再次回顯tree組件的選擇的這條數據
<el-tree ref="tree" class="select-tree" highlight-current :data="options" :props="props" node-key="id" :expand-on-click-node="false" :filter-node-method="filterNode" @node-click="onClickNode" :default-expanded-keys="[1]" ></el-tree>
首先 highlight-current,node-key 屬性要有
很簡單的一句代碼
created() { // 回顯tree的高亮 this.$nextTick(()=>{ this.$refs.tree.setCurrentKey(id) // 此時的id就是之前你選中的數據對應的id }) }