我找到了迈克·博斯托克的adjacency matrix visualization的GitHub version,使用的是《悲惨世界》中的数据。
我把它转换成了Vue3代码,但由于这是我的第一个项目,我可能犯了一些错误。应该添加到每行的单元格被添加到了主HTML中,可视化没有出现(黑屏)。
以下是Vue3格式的转换可视化的在线版本:https://codesandbox.io/s/sweet-gould-dejiuj?file=/src/components/Miserables.vue:33765-33857
1条答案
按热度按时间vfwfrxfs1#
这是因为方法
roww()
的上下文不是正确的上下文。使用以下代码创建一行:
最后一行为选择的每个节点调用
this.roww
,但该函数的上下文(this.roww
内的this
关键字)以某种方式硬编码到其所属的对象,因此它没有接收到正确的上下文,该上下文应该是与DOM相关的实际节点对象。为了解决这个问题,你需要使用一个用
function
关键字创建的常规函数(不是箭头函数,原因和上面一样),这样它就可以传递正确的上下文,尽管因为你的函数精确地依赖于它的“父”上下文(另一个this
),你将不得不在外部作用域中设置一个引用它的变量,这样它就可以在函数中被读取: