【发布时间】:2020-11-10 12:48:31
【问题描述】:
我使用以下命令安装了 phylotreejs:
npm install --save phylotree
当我尝试将其导入这样的页面时:
import * as d3 from 'd3';
import phylotree from 'phylotree/build/phylotree';
我收到以下错误:
Cannot read property 'phylotree' of undefined
如果我能理解这里发生的事情,那将非常有帮助。 我通过阅读 nuxt 文档 [https://nuxtjs.org/faq/]
阅读并尝试了以下内容import phylotree from '~/node_modules/phylotree/build/phylotree.js'
export default {
head () {
return {
script: [
{ src: '~/node_modules/phylotree/build/phylotree.js' }
],
}
},
}
但似乎没有任何效果
下面是Vue页面,我正在尝试创建:
<template>
<div>
<section class="section">
<div class="container">
<div id="phylotree"></div>
</div>
</section>
</div>
</template>
<script>
import * as d3 from 'd3';
import phylotree from 'phylotree';
import _ from 'lodash';
export default {
data:() => ({
example_tree : "(((EELA:0.150276,CONGERA:0.213019):0.230956,(EELB:0.263487,CONGERB:0.202633):0.246917):0.094785,((CAVEFISH:0.451027,(GOLDFISH:0.340495,ZEBRAFISH:0.390163):0.220565):0.067778,((((((NSAM:0.008113,NARG:0.014065):0.052991,SPUN:0.061003,(SMIC:0.027806,SDIA:0.015298,SXAN:0.046873):0.046977):0.009822,(NAUR:0.081298,(SSPI:0.023876,STIE:0.013652):0.058179):0.091775):0.073346,(MVIO:0.012271,MBER:0.039798):0.178835):0.147992,((BFNKILLIFISH:0.317455,(ONIL:0.029217,XCAU:0.084388):0.201166):0.055908,THORNYHEAD:0.252481):0.061905):0.157214,LAMPFISH:0.717196,((SCABBARDA:0.189684,SCABBARDB:0.362015):0.282263,((VIPERFISH:0.318217,BLACKDRAGON:0.109912):0.123642,LOOSEJAW:0.397100):0.287152):0.140663):0.206729):0.222485,(COELACANTH:0.558103,((CLAWEDFROG:0.441842,SALAMANDER:0.299607):0.135307,((CHAMELEON:0.771665,((PIGEON:0.150909,CHICKEN:0.172733):0.082163,ZEBRAFINCH:0.099172):0.272338):0.014055,((BOVINE:0.167569,DOLPHIN:0.157450):0.104783,ELEPHANT:0.166557):0.367205):0.050892):0.114731):0.295021)",
}),
mounted (){
// const phylotree = require('phylotree');
var tree = d3.layout.phylotree()
.svg(d3.select("#phylotree"));
tree(example_tree).layout();
}
};
</script>
<style scoped>
#spaced {
letter-spacing: 3px;
}
.section {
padding: 1.5rem 1.5rem;
}
</style>
【问题讨论】:
-
如果您完成了上述所有操作,您应该能够使用:
const phylotree = require('phylotree)'导入模块。这来自他们的文档:phylotree.hyphy.org/documentation/intro.html#installationimport phylotree from 'phylotree'也可能有效。 -
@LupuȘtefanAlex 我试过
const phylotree = require('phylotree'),正如你所指出的,但它似乎不起作用。var tree = d3.layout.phylotree()中仍然显示错误。
标签: vue.js d3.js vuejs2 nuxt.js