-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nuxt 3 support ? #62
Comments
Hello, I wrote a plugin for my use case, import { defineNuxtPlugin } from '#app';
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.provide('format',(rawtime)=>{
const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
// let date = new Date("2021-10-30T19:51:27.710Z");
let date = new Date(rawtime);
let year = date.getFullYear();
let month = date.getMonth();
let day = date.getDate();
let hh = date.getHours();
let mm = date.getMinutes();
let AmOrPm = hh >= 12 ? 'AM' : 'AM';
hh = (hh % 12) || 12;
let diffInSec = Math.floor((Date.now() - date) / 1000);
if(diffInSec < 30){
return 'Just Now';
}
if(diffInSec < 59){
return diffInSec + ' seconds ago';
}
let diffInMin = Math.floor(diffInSec/60);
if(diffInMin<59){
return diffInMin + ' mins ago';
}
return months[month] +' '+ day+' '+year+' , '+hh+':'+mm +' '+ AmOrPm;
});
}); But is it the right way of doing it ? or can I use dateFns as a plugin (I tried but failed to get it working) in nuxt ?? |
Hello I have found a way to import datefns within nuxt3 : //plugins\datefns.ts
import * as datefns from 'date-fns'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide('datefns', datefns)
}) |
This will import FULL date-fns without tree shaking, even tho you might only use a few functions of it. I highly recommend not doing that. If you want to use date-fns within your client- or server-code (but not in template) there is no need to use this module! This module is just needed if you want to use date-fns function within your templates. Be aware that until date-fns 3.0 is released date-fns is not working on edge workers (like Cloudflare Workers or Vercel Edge Functions): nitrojs/nitro#1889 |
On our project we use only few functions. import {format,parse, parseISO, getDay} from 'date-fns'
const datefns: any={
format,
parse,
parseISO,
getDay
}
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide('datefns', datefns)
}) |
repo: https://github.com/productfrontenddeveloper/nuxt3_bug
nuxt/bridge#226
The text was updated successfully, but these errors were encountered: