如何在 nuxtjs 中设置服务器日期配置
how can set server date config in nuxtjs
我想比较客户端中的两个日期。其中一个是当前日期,其准确性取决于用户系统日期的准确性。
我也使用 nuxt.js。有什么方法可以在 nuxt 中设置一些东西并从客户端的 nuxt(server) 获取日期。
不幸的是搜索了很多但一无所获。也许我的搜索不正确。
您可以使用 nuxtServerInit
方法并从此处生成时间戳:
在store/index.js
中:
actions: {
nuxtServerInit ({ commit }) {
commit('setNuxtTime', (new Date()).getTime())
}
}
If the action nuxtServerInit
is defined in the store, Nuxt.js will
call it with the context (only from the server-side). It's useful when
we have some data on the server we want to give directly to the
client-side.
https://nuxtjs.org/guide/vuex-store#the-nuxtserverinit-action
我想比较客户端中的两个日期。其中一个是当前日期,其准确性取决于用户系统日期的准确性。
我也使用 nuxt.js。有什么方法可以在 nuxt 中设置一些东西并从客户端的 nuxt(server) 获取日期。 不幸的是搜索了很多但一无所获。也许我的搜索不正确。
您可以使用 nuxtServerInit
方法并从此处生成时间戳:
在store/index.js
中:
actions: {
nuxtServerInit ({ commit }) {
commit('setNuxtTime', (new Date()).getTime())
}
}
If the action
nuxtServerInit
is defined in the store, Nuxt.js will call it with the context (only from the server-side). It's useful when we have some data on the server we want to give directly to the client-side.
https://nuxtjs.org/guide/vuex-store#the-nuxtserverinit-action