Comments (2)
when I use fetch for creating a dayjs object, I can not access it later in a component.
Nuxt.js uses window.__NUXT__
for universal behavior between SSR / SPA.
This is limited to POJOs (Plain Old JavaScript Objects) and not POJOs, as Day.js objects have functions.
Therefore, the following code is the correct code.
// store/index.js
export const state = () => ({
dateTime: null
});
export const mutations = {
SET_DATE_TIME(state, obj) {
state.dateTime = obj;
}
};
export const actions = {
setDateTime({ commit, state, $dayjs }) {
commit("SET_DATE_TIME", this.$dayjs().format()); // to ISO8601 string
console.log(state.dateTime);
}
};
<template>
<!-- pages/index.vue -->
<section>
<div>
<h2>{{ $dayjs(dateTime).format("YYYY-MM-DD") }}</h2>
</div>
</section>
</template>
<script>
import { mapState } from "vuex";
export default {
async fetch({ store }) {
await store.dispatch("setDateTime");
},
computed: {
...mapState(["dateTime"]),
},
};
</script>
<style scoped>
.title {
font-family: "Quicksand", "Source Sans Pro", -apple-system, BlinkMacSystemFont,
"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
display: block;
font-weight: 400;
font-size: 100px;
color: #2E495E;
letter-spacing: 1px;
font-size: 6em;
}
.green {
color: #00C48D;
}
.subtitle {
font-weight: 300;
font-size: 3em;
color: #2E495E;
word-spacing: 5px;
padding-bottom: 15px;
}
.links {
padding-top: 15px;
}
</style>
from dayjs-module.
Thank you for clarification @potato4d!
from dayjs-module.
Related Issues (20)
- Jest testing: TypeError: $dayjs is not a function HOT 4
- update dayjs to latest version (1.10.4) HOT 2
- Set defaultTimeZone from store? HOT 3
- Locales and defaultLocale HOT 1
- Vite support
- Dependency Dashboard
- Question: How to use updateLocale in nuxtjs/dayjs? HOT 2
- Nuxt warning occurs when this module is used HOT 1
- TS2345: Argument of type 'string' is not assignable to parameter of type HOT 3
- Plugin list without extension not working anymore
- Nuxt3 Support HOT 15
- [Nuxt Bridge] Build tries to import plugin without file format HOT 1
- Discussion for @nuxtjs/dayjs version 2 HOT 2
- dayjs reverts to defaultLocale when rendered server side HOT 1
- Parse from specific locale ?
- Registering a local plugin
- Stopped working in nuxt 3.0.0-rc.14 HOT 9
- Day JS in Nuxt guessing timezone using tz.guess() not a function
- Nuxt 3 Support HOT 1
- Error on creating a new locale, for Latin language.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dayjs-module.