【问题标题】:Vuejs use NeDB,can not find database filesVuejs使用NeDB,找不到数据库文件
【发布时间】:2017-05-15 17:46:47
【问题描述】:

Vue 创建项目:

vue init webpack-simple nedbtest

安装Nedb数据库:

npm i nedb -S

更改App.vue

<template>
<div>
  <button @click="insert">insertData</button>
  <button @click="find">FindData</button>
</div>
</template>

<script>
  var Datastore = require('nedb')
  var db = new Datastore({filename:'./test.db', autoload:true})
  export default {
    name: 'app',
    methods:{
      insert () {
        db.insert({name:"admin", password:"123"}, function(err, res) {
          console.log(res)
        })
      },
      find () {
        db.find({}, function(err, res) {
          console.log(res)
        })
      },
    }
  }
</script>

test.db 文件在哪里?我找不到这个文件!使用Nodejs的时候可以找到这个文件。

【问题讨论】:

    标签: vue.js vuejs2 nedb


    【解决方案1】:

    正如文档中的here 所说:

    在浏览器版本中,如果指定文件名,数据库将是持久化的,并且 自动选择可用的最佳存储方法(IndexedDB, WebSQL 或 localStorage)取决于浏览器。

    这意味着“文件名”必须存储在这两种方法中的某处,具体取决于浏览器。

    我从未使用过这个项目,但我想它必须将文件名提供给 indexDB 中的数据库,或者提供给 localStorage 值的键等...

    【讨论】:

    • 感谢您的回答!
    【解决方案2】:

    自述文件中解释说,在浏览器版本中,数据库被持久化到浏览器中可用的最佳存储选项,包括 indexedDB、localstorage 等。

    你在硬盘上找不到这个文件,因为浏览时代不允许脚本创建文件。

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 2021-11-08
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      相关资源
      最近更新 更多