我正在尝试使用dree将文件夹结构作为json对象获取。
我已通过以下链接安装了软件包:https://www.npmjs.com/package/dree
为了测试,我在项目中提供了我的components文件夹的路径
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App "/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
const dree = require('dree');
const tree = dree.scan('./components');
console.log(tree);
export default {
name: 'app',
components: {
HelloWorld
}
}
</script>
如果我使用console.log(dree),那么它给了我结果,但是console.log(tree);给我以下错误。请帮助。
index.js?517d:325未捕获的TypeError:无法在Object.scan(index.js?517d:325)设置属性'sizeInBytes'为null enter code here
Dree使用节点fs模块,浏览器不支持此模块。因此,浏览器不支持dree。
这里您可以找到有关模块的有用信息,而在vuejs中没有使用浏览器支持,也许您可以在构建时而不是运行时使用它。