How to use global variable #1366
Unanswered
akbarism
asked this question in
Help and Questions
Replies: 1 comment
-
Just import dayjs (everywhere). You don’t need to provide that kind of variables |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
so i use dayjs on my vue project, and declare it as a global variable
this is my configuration :
on dayjs.js :
import dayjs from "dayjs";
export const dayConfig = (app) => { app.provide("day", dayjs); };
on main,js :
import { dayConfig } from "./plugins/Dayjs";
dayConfig(app);
in component.vue I use it like this :
import { inject } from "vue";
const day = inject("day");
const date = day().format('YYYY-MM-DD')
if I use that method in store.js it will display a warning:
inject() can only be used inside setup() or functional components.
Beta Was this translation helpful? Give feedback.
All reactions