【问题标题】:npm dree folder structure to JSONnpm dree 文件夹结构转 JSON
【发布时间】:2020-01-13 14:09:43
【问题描述】:

我正在尝试使用 dree 将文件夹结构获取为 json 对象。

我已经按照以下链接安装了软件包:https://www.npmjs.com/package/dree

为了测试,我已经在我的项目中给出了组件文件夹的路径

<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 Uncaught TypeError: Cannot set property 'sizeInBytes' of nullenter code here at Object.scan (index.js?517d:325)

【问题讨论】:

  • 这个库似乎是 node.js 只是因为它通过目录路径。您不能在浏览器中使用它。

标签: vue.js npm directory-structure


【解决方案1】:

Dree 使用 node fs 模块,浏览器不支持该模块。因此,浏览器不支持 dree。

在这里您可以找到有关在 vuejs 中使用的不支持浏览器的模块的有用信息,也许您可​​以在构建时而不是运行时使用它。

Unable to require 'fs' with Vue CLI 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    • 2014-07-11
    • 2021-07-15
    • 1970-01-01
    • 2020-10-08
    • 2021-11-18
    • 2021-04-11
    相关资源
    最近更新 更多