Skip to content

Commit 69d47e3

Browse files
committed
fix: tree expandedKeys push #239
1 parent 8e37cd8 commit 69d47e3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

components/vc-tree/src/Tree.jsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ import {
2121
* other props can pass with context for future refactor.
2222
*/
2323

24+
function getWatch (keys = []) {
25+
const watch = {}
26+
keys.forEach(k => {
27+
watch[k] = function () {
28+
this.needSyncKeys[k] = true
29+
}
30+
})
31+
return watch
32+
}
33+
2434
const Tree = {
2535
name: 'Tree',
2636
mixins: [BaseMixin],
@@ -91,6 +101,7 @@ const Tree = {
91101
}),
92102

93103
data () {
104+
this.needSyncKeys = {}
94105
const state = {
95106
_posEntities: {},
96107
_keyEntities: {},
@@ -124,8 +135,10 @@ const Tree = {
124135
},
125136

126137
watch: {
138+
...getWatch(['treeData', 'children', 'expandedKeys', 'autoExpandParent', 'selectedKeys', 'checkedKeys', 'loadedKeys']),
127139
__propsSymbol__ () {
128140
this.setState(this.getDerivedStateFromProps(getOptionProps(this), this.$data))
141+
this.needSyncKeys = {}
129142
},
130143
},
131144

@@ -135,9 +148,9 @@ const Tree = {
135148
const newState = {
136149
_prevProps: { ...props },
137150
}
138-
151+
const self = this
139152
function needSync (name) {
140-
return (!_prevProps && name in props) || (_prevProps && _prevProps[name] !== props[name])
153+
return (!_prevProps && name in props) || (_prevProps && self.needSyncKeys[name])
141154
}
142155

143156
// ================== Tree Node ==================

0 commit comments

Comments
 (0)