小编Sag*_*ira的帖子

如何从主node.js脚本运行多个node.js脚本?

我对node.js完全不熟悉.我有两个我想运行的node.js脚本.我知道我可以单独运行它们但我想创建一个运行这两个脚本的node.js脚本.应该是主node.js脚本的代码?

javascript jquery node.js

11
推荐指数
1
解决办法
1万
查看次数

Vercel 生产环境中的动态路由重定向到 404

我在 Vercel 上托管了一个盖茨比博客。对于我的主页,我从 Mongo Atlas 获取动态内容。

我正在盖茨比中创建动态路线

  createPage({
    path: '/microblog/:id',
    matchPath: '/microblog/:id',
    component: path.resolve(`./src/pages/index.jsx`),
  });
Run Code Online (Sandbox Code Playgroud)

当我在本地请求/microblog/5f3114b3e096870008336d7c(现在使用 vercel 运行)时,它可以工作,但在产品上,您可以看到它重定向到 404 (https://sagark.dev/microblog/5f3114b3e096870008336d7c

另外,如果网站已完全呈现。该链接有效。我认为问题与 Vercel 动态路由有关,或者我遗漏了一些东西。

gatsby vercel

5
推荐指数
0
解决办法
748
查看次数

如何在不使用input元素的情况下捕获Vuejs中的任何按键事件

我正在制作一种游戏,我希望用户输入一个特定的单词,然后我想检查是否按下了特定的单词.如果单词被按下,我将获取下一个单词.目前我正在使用表单并使用了如下所示的v-model:

 <input v-model="inputSpell">
Run Code Online (Sandbox Code Playgroud)

在Vue实例中,我使用了watch属性,该属性不断检查输入的单词是否与被询问的单词匹配.

watch : {

    inputSpell : function() {
        var spellCount = this.spellCount;
        var inputSpell = this.inputSpell.toUpperCase();
        var presentSpell = this.presentSpell;

        console.log("Spell Count " + spellCount);
        console.log("Input Spell " + inputSpell);
        console.log("Present Spell" + presentSpell);

        if (inputSpell.length === 3 && inputSpell === presentSpell) {
            this.$set(this, 'inputSpell', '');
            if (spellCount === 3) {
                return this.completeCombo();
            }
            return this.fetchSpell(spellCount);
        }

        if (inputSpell.length >=3) {
            this.$set(this, 'inputSpell', '');
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想到了三个想法:

  1. 上面我正在做的是显示表格.用户输入该表单中的单词.看起来不太好看.

  2. 在加载游戏时,使输入元素隐藏并专注于它.但缺点是如果用户点击页面上的任何地方,表单上的焦点将会丢失.

  3. 制作自定义指令或调用捕获按键事件以检查单词的方法.

任何帮助将不胜感激.

谢谢.

javascript vue.js vue-resource

4
推荐指数
1
解决办法
4951
查看次数

迭代 mongo 数据的更快方法是什么?批量查找与光标迭代?

我的 mongo 集合中有超过 1000 万条记录,我想将它们移动到其他数据库。

有两种方法可以实现这一目标:

使用 find 批量数据

const batchSize = 1000;
const collection = mongo.client.collection('test');
const count = await quizVersionCollection.count();
let iter = 0;
while (iter * batchSize <= count) {
  const dataArr = await collection.find({})
                  .sort({ _id: -1 })
                  .limit(batchSize)
                  .skip(iter * batchSize)
                  .toArray();
  iter += 1;
}
Run Code Online (Sandbox Code Playgroud)

使用 mongo 游标

while (yield cursor.hasNext()) {
    const ids = [];
    const batchSize = 1000;
    for (let i = 0; i < batchSize; i += 1) {
      if (yield …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js

1
推荐指数
1
解决办法
2752
查看次数

标签 统计

javascript ×2

node.js ×2

gatsby ×1

jquery ×1

mongodb ×1

vercel ×1

vue-resource ×1

vue.js ×1