element [bug report] what does the depth of El tree node data response have to do with?

kg7wmglp  于 2023-02-04  发布在  其他
关注(0)|答案(5)|浏览(229)

Element UI version

2.15.1

OS/Browsers version

mac

Vue version

2.6.10

https://jsfiddle.net/5pjnqs4u/5/

Steps to reproduce

<template>
  <div class="custom-tree-container">
    <el-button @click="add()">testbutton</el-button>
    <div class="block">
      <p>render-content</p>
      <el-tree
        :data="data"
        node-key="id"
        ref="sideTree"
        :expand-on-click-node="true">
      </el-tree>
    </div>

  </div>

</template>
<script>

export default {
  data() {
    return {
      id: 0,
      // data: this.$store.state.sidebar.menu
      data: [
        {
          id: 1,
          label: 'nodea',
          children: [
            {
              id: 3,
              label: 'nodea3',
              children: [{
                id: 5,
                label: 'nodea5',
              }],
            }, {
              id: 4,
              label: 'nodea4',
              children: [],
            }
          ],
        }, {
          id: 2,
          label: 'nodeb',
          children: {}
        }
      ]
    }
  },
  mounted() {
    this.data.push({
      id: 117,
      label: 'oooo',
      children: [],
    })
    // this.data.splice(1, 1)
    console.log('children:', this.data[0].children[0].children)
    this.data[0].children[0].children.push({
      id: 817,
      label: 'xxxx',
      children: [],
    })
    // console.log("data,", this.data)
  },
  methods: {
    add() {
      this.data[0].children[0].children.push({
        id: 1017,
        label: 'addxxxx',
        children: [],
      })
    },
  }
};
</script>

What is Expected?

  1. 页面初次载入后,应该可以看到节点xxxx,但是并没有.
    节点ooo可以看到.

What is actually happening?

  1. 没有看到节点xxxx,但是看到了节点oooo
  2. 点击testbutton,然后看到了节点xxxx和addxxxx
ubof19bj

ubof19bj1#

Translation of this issue:

Element UI version

2.15.1

OS/Browsers version

mac

Vue version

2.6.10

https://elementui.github.io/issue-generator

Steps to reproduce

<template>
<div class=\"custom-tree-container\">

<el-button @click=\"add()\">testbutton</el-button>
<div class=\"block\">

<p>render-content</p>
<el-tree

:data=\"data\"
node-key=\"id\"

ref=\"sideTree\"
:expand-on-click-node=\"true\">

</el-tree>
</div>

</div>
</template>

<script>
export default {

data() {
return {

id: 0,
// data: this.$ store.state.sidebar .menu

data: [
{

id: 1,
label: 'nodea',

children: [
{

id: 3,
label: 'nodea3',

children: [{
id: 5,

label: 'nodea5',
}],

}, {
id: 4,

label: 'nodea4',
children: [],

}
],

}, {
id: 2,

label: 'nodeb',
children: {}

}
]

}
},

mounted() {
this.data.push ({

id: 117,
label: 'oooo',

children: [],
})

//  this.data.splice (1, 1)
console.log ('children:',  this.data [0].children[0].children)

this.data [0].children[0]. children.push ({
id: 817,

label: 'xxxx',
children: [],

})
//  console.log (\"data,\",  this.data )

},
methods: {

add() {
this.data [0].children[0]. children.push ({

id: 1017,
label: 'addxxxx',

children: [],
})

},
}

};
</script>

What is Expected?

  1. After loading the page for the first time, you should be able to see the node xxxxx, but it doesn't
    Node OOo can be seen

What is actually happening?

  1. We don't see node XXX, but we see node oooo
  2. Click testbutton, and then you can see the nodes xxxxx and addxxxxx
5us2dqdw

5us2dqdw2#

数组的深度为1时的push,能够得到view的响应,但是深度为3时就得不到了view的响应,感觉很奇怪.

ldxq2e6h

ldxq2e6h4#

there are two ways two fix this problem:

  1. set default-expand-all true
  2. use PR Tree: Data may be changed before node is created. #20884 #20905
3okqufwl

3okqufwl5#

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

相关问题