vue3-usecookies
v1.0.6
Published
This package provide hook for comfortable usage cookies.
Downloads
7
Readme
Vue3-useCookies
This package provide hook for comfortable usage cookies.
Installation
npm install vue3-usecookies
Examples
Return reactive string with cookies
const { cookies } = useCookies();
// 'auth=true'
Set cookie.
const { setCookie } = useCookies();
setCookie(
{ key: "auth", value: true },
{
path: "/",
expires: new Date(),
secure: true,
}
);
Get cookie.
const { getCookie } = useCookies();
const isAuth = JSON.parse(getCookie("auth"));
Return reactive object with all cookies.
const { getCookies } = useCookies();
const cookies = getCookies();
// {auth: 'true'}
Delete cookie by key.
const { deleteCookie } = useCookies();
deleteCookie("auth");