mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 18:37:43 +08:00
Demo:修复节点文字数量计数不正确的问题
This commit is contained in:
parent
e584081b41
commit
a6fff7f7a3
@ -17,11 +17,14 @@
|
||||
* @Date: 2021-06-24 22:53:10
|
||||
* @Desc: 字数及节点数量统计
|
||||
*/
|
||||
|
||||
let countEl = document.createElement('div')
|
||||
export default {
|
||||
name: 'Count',
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
textStr: '',
|
||||
words: 0,
|
||||
num: 0
|
||||
}
|
||||
@ -39,9 +42,12 @@ export default {
|
||||
* @Desc: 监听数据变化
|
||||
*/
|
||||
onDataChange(data) {
|
||||
this.textStr = ''
|
||||
this.words = 0
|
||||
this.num = 0
|
||||
this.walk(data)
|
||||
countEl.innerHTML = this.textStr
|
||||
this.words = countEl.textContent.length
|
||||
},
|
||||
|
||||
/**
|
||||
@ -51,7 +57,7 @@ export default {
|
||||
*/
|
||||
walk(data) {
|
||||
this.num++
|
||||
this.words += (String(data.data.text) || '').length
|
||||
this.textStr += String(data.data.text) || ''
|
||||
if (data.children && data.children.length > 0) {
|
||||
data.children.forEach(item => {
|
||||
this.walk(item)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user