小编Pro*_*fer的帖子

如何从gatsby的路由中删除“ / app”

我已经安装了gatsby项目,并且/app由于这个gatsbynodejs文件,我的路线仅在包含它时才起作用。

exports.onCreatePage = async ({ page, actions }) => {
  const { createPage } = actions
  // page.matchPath is a special key that's used for matching pages
  // only on the client.
  if (page.path.match(/^\/app/)) {
    page.matchPath = "/app/*"

    // Update the page.
    createPage(page)
  }
}
Run Code Online (Sandbox Code Playgroud)

我需要/app从所有组件中删除。有可能这样做吗?

而且在生产模式下,我的动态路线不起作用是什么问题?

const App = () => (
  <Layout>
    <Router>
      <VerifyToken path="/app/:token"/>
      <MagicLink path="/app/link/:magicLink"/>
    </Router>
  </Layout>
)
Run Code Online (Sandbox Code Playgroud)

reactjs gatsby

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

通过添加标题和一些计算数据将两个excel数据导出到单个excel表中

我正在使用react-data-export在我的反应项目中导出 Excel 表。我需要在单个文件中导出两个 excel 数据。例子

在此处输入图片说明

如果上述模块不可能,请建议我一种新的方法。

javascript csv excel node.js reactjs

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

使用 moment 将当前时间转换为毫秒

假设我有这个时间

'2018-08-03T15:53:57.000Z'
Run Code Online (Sandbox Code Playgroud)

我只需要将时间部分转换为milliseconds

我尝试了这个,但没有成功并抛出错误

moment.utc("2018-08-03T15:53:57.000Z").format('HH:mm:ss').milliseconds()
Run Code Online (Sandbox Code Playgroud)

错误

TypeError: (0 , _moment2.default)(...).format(...).milliseconds is not a function
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我如何将时间转换为毫秒吗?

谢谢你!!!

javascript momentjs

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

如何在盖茨比中创建动态路线

我已经使用此链接设置了gatsby项目。它工作正常。

现在,我知道如何通过在pages文件夹内定义组件来创建路由。但是现在我面临一个新的挑战,我需要创建一条动态路线,以便我可以通过id它(就像一样reactjs)。

<Route path: "/path/:id"/>
Run Code Online (Sandbox Code Playgroud)

我该如何在盖茨比做到这一点?

reactjs react-router gatsby

4
推荐指数
2
解决办法
2727
查看次数

如何使用 momentjs 获取 3 个字母的时区?

我使用矩库使用以下代码获取时区

console.log(moment.tz.names())
Run Code Online (Sandbox Code Playgroud)

这给了我以下格式的结果

0: "Africa/Abidjan"
1: "Africa/Accra"
2: "Africa/Addis_Ababa"
3: "Africa/Algiers"
4: "Africa/Asmara"
5: "Africa/Asmera"
6: "Africa/Bamako"
Run Code Online (Sandbox Code Playgroud)

我只需要得到类似的缩写

在此输入图像描述

力矩可以提供这样的灵活性吗?我还需要偏移量吗?

谢谢你!!!

javascript timezone timezone-offset momentjs

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

如何在React Gatsby中获取先前的URL

我用非常熟悉的React.js,但新Gatsby

我要在中检测上一页URL Gatsby

javascript static-site reactjs gatsby

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

如何在 gatsby 的布局文件中获取路径名

我正在使用gasby,这里的主文件始终layout.js是它们的父文件。既然它是一个父文件,那么我怎样才能this.props.location.pathname在其中获取位置道具?

这是我的布局组件

class Layout extends Component {
  componentWillMount() {
    console.log(this.props, 'dssssssssssssf')
  }

  render() {
    const { children } = this.props
    return(
      <StaticQuery
        query={graphql`
          query SiteTitleQuery {
            site {
              siteMetadata {
                title
              }
            }
          }
        `}
        render={data => (
          <>
            <div>
              <Provider store={store}>
                {children}
              </Provider>
            </div>
          </>
        )}
      />
    )
  }
}
Layout.propTypes = {
  children: PropTypes.node.isRequired
}

export default Layout.
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router gatsby

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

Promise.all或嵌套异步等待哪个更好?

我有两个代码块。首先是使用async await

  async sendEmailNotifications() {
    try {
      const users = await User.find(...)

      const promises = users.map(async(user) => {
        const _promises = user.appId.map(async(app) => {
            const todayVisitorsCount = await Session.count({...})
            const yesterdayVisitorsCount = await UserSession.count({...})
            const emailObj = {
              todayVisitorsCount,
              yesterdayVisitorsCount
            }
            const sendNotification = await emailService.analyticsNotification(emailObj)
        })
        await Promise.all(_promises)
      })
      return promises
    } catch (err) {
      return err
    }
  }
(await sendEmailNotifications())
Run Code Online (Sandbox Code Playgroud)

然后我有使用 Promise.all

    sendEmailNotifications() {
      const users = await User.find(...)
      const promises = users.map((user) => {
        const allPromises …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js promise async-await

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

只需要获取小数点后两位

我有以下格式的字符串

const number = "21708.333333333336"
Run Code Online (Sandbox Code Playgroud)

然后我将它传递给函数以获取这种格式的数字

"21,708.333333333336"
Run Code Online (Sandbox Code Playgroud)

我用来执行此操作的函数(我已经尝试过)

let numberFormat = (x) => {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
Run Code Online (Sandbox Code Playgroud)

但我只需要最后 2 位数字

"21,708.33"
Run Code Online (Sandbox Code Playgroud)

这个的正则表达式应该是什么?

javascript regex

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

禁用按钮,直到 Formik 中填写所有表单字段

我正在使用 Formik 形式。我里面有两个字段。我需要禁用保存按钮,直到两个字段都被填满。

<Formik initialValues={initialValues} validationSchema={validate} onSubmit={() => this.handleSubmit()}>
  {({ values, handleChange, handleSubmit, setValues, isSubmitting }) => (
    <form onSubmit={handleSubmit} noValidate>
      <div>
        <div onClick={this.showDrawer}>
          <h6>Select Company </h6>
          <input name="customer" readOnly placeholder="Select" value={values.customer} type="text" />
        </div>
        <ErrorMessage component="span" name="customer" />
      </div>
      <div>
        <div onClick={this.showDrawer}>
          <h6>Select Driver</h6>
          <input name="driver" readOnly placeholder="Select" value={values.driver} type="text" />
        </div>
        <ErrorMessage component="span" name="driver"/>
      </div>
      <button type="submit" disabled={isSubmitting}>
        Save
      </button>
    </form>
  )}
</Formik>
Run Code Online (Sandbox Code Playgroud)

javascript forms reactjs formik

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