小编Seb*_*ian的帖子

VS Code search.exclude不起作用

我无法进行search.exclude设置,因此它不包含build文件夹。

这是屏幕截图: 在此处输入图片说明

ide visual-studio-code

11
推荐指数
2
解决办法
2972
查看次数

在React中删除事件侦听器(lodash.throttle)

嘿stackoverflowers,

removeEventListener()当我不使用throttle()lodash时工作.

   window.addEventListener('scroll', this.checkVisible, 1000, false);
     window.removeEventListener('scroll', this.checkVisible, 1000, false);
Run Code Online (Sandbox Code Playgroud)

(我绑定了构造函数中的方法)


不幸的是,throttle(this.checkVisible)功能缠绕它 - 不起作用.我认为这是因为当尝试删除监听器时,throttle()会生成新的实例,也许我应该全局绑定它.怎么样(如果是这样的话)?

  import React from 'react';
    import throttle from 'lodash.throttle';

    class About extends React.Component {
      constructor(props) {
        super(props);

        this.checkVisible = this.checkVisible.bind(this);
      }

      componentDidMount() {
        window.addEventListener('scroll', throttle(this.checkVisible, 1000), false);

      }

      checkVisible() {
       if (window.scrollY > 450) {
        // do something
        window.removeEventListener('scroll', throttle(this.checkVisible, 1000),
        false);
        }
      }

      render() {
        return (
          <section id="about"> something
          </section>
        );
      }
    }

    export default About;
Run Code Online (Sandbox Code Playgroud)

谢谢,善意的人!

javascript events javascript-events reactjs

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

React Admin-如何使用abc / def之类的嵌套路径调用dataProvider

React-admin的Resource组件将nameprop值映射到一个端点。

例如从访问数据。http://example.com/abc,您的Resource组件如下所示: <Resource name='abc'/>

我要访问什么资源http://example.com/abc/def?这<Resource name='abc/def'/>甚至不调用该dataProvider函数。

我不想以如下丑陋的解决方案结束:

// App.js
<Resource name='def'/>
Run Code Online (Sandbox Code Playgroud)
// dataProvider.js
if (resource==='def') {
url = 'abc/def'
}
Run Code Online (Sandbox Code Playgroud)

资源名称是否必须始终没有/?有骇客吗?

admin-on-rest react-admin

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

是否可以在 javascript 的字符串中使用 emmet 的 lorem?

我想让埃米特帮我解决这个问题:

const str = 'lorem5|TAB'; --> const str = 'Lorem ipsum dolor sit amet.';
Run Code Online (Sandbox Code Playgroud)

|光标位置

TAB点击选项卡

在 VSCode 中可以吗?它仅对我有用jsxhtml

emmet visual-studio-code

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

为什么我不能返回箭头功能?

我在这里有一个高阶sorta函数.

虽然这按预期工作:

var square = (a) => a * a;

var callAndLog = (func) => {
  return function () {
    var res = func.apply(undefined, arguments);
    console.log("Result is: " + res);
    return res;
  }
};

var squareAndLog = callAndLog(square);

squareAndLog(5);  // Result is 25
Run Code Online (Sandbox Code Playgroud)

这里,当我返回一个箭头功能时,它不起作用:

var square = (a) => a * a;
var callAndLog = (func) => {
  return (() => {
    var res = func.apply(undefined, arguments);
    console.log("Result is: " + res);
    return res;
  })
};
var squareAndLog = callAndLog(square); …
Run Code Online (Sandbox Code Playgroud)

javascript higher-order-functions ecmascript-6 arrow-functions

3
推荐指数
2
解决办法
1136
查看次数

在Gatsby中设置环境变量

我使用了这个教程:https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/environment-variables.md

我遵循的步骤:

1)安装dotenv@4.0.0

2)在根文件夹中创建两个文件:".env.development"和".env.production"

3)"按照他们的设置说明"(dotenv npm docs上的示例)

gatsby-config.js:

const fs = require('fs');
const dotenv = require('dotenv');
const envConfig = 
dotenv.parse(fs.readFileSync(`.env.${process.env.NODE_ENV}`));
for (var k in envConfig) {
  process.env[k] = envConfig[k];
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我跑步时gatsby develop,NODE_ENV尚未设定:

error Could not load gatsby-config


  Error: ENOENT: no such file or directory, open 'E:\Front-End Projects\Gatsby\sebhewelt.com\.env.undefined'
Run Code Online (Sandbox Code Playgroud)

它在我手动设置时有效:

dotenv.parse(fs.readFileSync(`.env.development`));
Run Code Online (Sandbox Code Playgroud)

我需要gatsby-config中的环境变量,因为我将敏感数据放在这个文件中:

  {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: envConfig.CONTENTFUL_SPACE_ID,
        accessToken: envConfig.CONTENTFUL_ACCESS_TOKEN
      }
    }
Run Code Online (Sandbox Code Playgroud)

如何使它工作?

PS:附加问题 - 因为这让我想到,我知道我不应该在github上放置密码和令牌,但是当从github构建netlify时,还有其他安全方法吗?

javascript environment-variables node.js contentful gatsby

3
推荐指数
2
解决办法
3249
查看次数

如何在 Gatsby.js 中将时间戳附加到 Markdown 前面的内容

我正在浏览 Gatsby 示例入门博客,这是 Markdown 博客文章之一:

https://raw.githubusercontent.com/gatsbyjs/gatsby-starter-blog/master/src/pages/2015-05-01-hello-world/index.md

我认为作者不会像date: "2015-05-01T22:12:03.284Z"每次发帖一样在前面硬输入一个字符串。

这是vim的功能吗?如何在保存文件时自动向 Gatsby 的 Markdown 文件添加时间戳?

帮助表示赞赏:)

javascript markdown gatsby

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

使用Netlify CMS在Hugo数据文件中收集

我正试着用Hugo ssg使用Netlify CMS.

我用:

netlify-cms@1.0
hugo@0.29
Run Code Online (Sandbox Code Playgroud)

我有一个简单的netlify-cms config.yml,有两个集合:帖子和作者.

  backend:
    name: github
    repo: sebhewelt/atlas
    branch: master

  display_url: https://mypage.com
  publish_mode: editorial_workflow  
  media_folder: "static/uploads"
  public_folder: "/uploads"
  collections:

    - label: "Posts"
      name: "post"
      folder: "content"
      create: true
      slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
      fields:
        - { label: "Title", name: "title", widget: "string" }
        - { label: "Publish Date", name: "date", widget: "datetime" , format: "YYYY-MM-DD hh:mma"}
        - { label: "Body", name: "body", widget: "markdown" }


    - label: "Authors"
      name: "author"
      folder: "data"
      create: true
      fields:
        - {label: "Name", …
Run Code Online (Sandbox Code Playgroud)

netlify netlify-cms

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