由于数据是后端返回的,直接返回handler:"(node)=>this.handleClick(node)" 则 value 会被转义 `
handler:"(node)=>this.handleClick(node)"
const vm = this
所以最理想的解决方式是由前端修改
this
handler:(node)=>vm.handleClick(node)
methods: { getTree() { this.$axios .get('/tree') .then((res) => { const results = res.results let vm = this function deepClone(originObject) { var deepObject = Array.isArray(originObject) ? [] : {} if (originObject && typeof (originObject) === 'object') { for (var key in originObject) { originObject['handler'] = (node) => { vm.handleClick(node) } // 如果子属性为引用数据类型,递归复制 if (originObject.hasOwnProperty(key)) { if (originObject[key] && typeof originObject[key] === 'object') { deepObject[key] = deepClone(originObject[key]) } else { deepObject[key] = originObject[key] } } } } return deepObject } this.devicesData = deepClone(results) }) .catch((e) => { this.$q.notify({ message: '接口请求出错', position: 'top', timeout: 1500, color: '#fff', }) }) }, handleClick(node) { console.log(JSON.stringify(node),"已经拿到当前node节点") }, },
codepen 解决地址
解决方法 修改数据结构
参考链接
强烈建议解决方案
由于数据是后端返回的,直接返回
handler:"(node)=>this.handleClick(node)"
则 value 会被转义 `const vm = this
所以最理想的解决方式是由前端修改
this
handler:(node)=>vm.handleClick(node)