我已经安装了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) 假设我有这个时间
'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)
有人可以帮助我如何将时间转换为毫秒吗?
谢谢你!!!
我已经使用此链接设置了gatsby项目。它工作正常。
现在,我知道如何通过在pages文件夹内定义组件来创建路由。但是现在我面临一个新的挑战,我需要创建一条动态路线,以便我可以通过id它(就像一样reactjs)。
<Route path: "/path/:id"/>
Run Code Online (Sandbox Code Playgroud)
我该如何在盖茨比做到这一点?
我使用矩库使用以下代码获取时区
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)
我只需要得到类似的缩写
力矩可以提供这样的灵活性吗?我还需要偏移量吗?
谢谢你!!!
我用非常熟悉的React.js,但新Gatsby。
我要在中检测上一页URL 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) 我有两个代码块。首先是使用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) 我有以下格式的字符串
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)
这个的正则表达式应该是什么?
我正在使用 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 ×8
reactjs ×6
gatsby ×4
momentjs ×2
node.js ×2
react-router ×2
async-await ×1
asynchronous ×1
csv ×1
excel ×1
formik ×1
forms ×1
promise ×1
regex ×1
static-site ×1
timezone ×1