- API 路由统一: 移除 /api/h5/,统一 /api/pms/ 入口 - 二进制改名: api-server -> pms-api(与服务名一致) - nginx: 合并 /api/ + /pms/api/ 为 /api/pms/ - 新增 docs/API.md 接口文档 - 后端: CabinetDetail 增加 rssi/pow_fail/address/soc 等字段 - Redis 管道批量读取仓体实时数据(SOC/电压/电流/功率) - DB: 所有 TIMESTAMP 列改为 DATETIME(修复类型不匹配) - 用户管理: 新增创建时间/修改时间列,状态改用 Switch - 角色管理/用户管理: 操作按钮改为图标 - PC 设备详情: 基本信息补全 RSSI/ICCID/电源/地址 - PC 卡片: 通道统计改用 Lucide 图标,颜色统一 - PC 二维码: canvas 渲染,含编号文字,支持右键下载 - H5: 按 uni-app 规范修正导航(navigateTo 替代 reLaunch) - H5: 详情页加返回导航条 - H5: 扫码支持摄像头(jsQR)+ ?id= 参数 - H5: 底部 tabBar 在所有页面常显 - H5: 首页统计改为 6 项(设备/通道/空闲/充电/充满/故障) - H5: 下拉刷新 / 上拉加载 - 产品首页: 添加业务联系 - 文档: 清理过时文件,补充缺失规范章节
4.9 KiB
category
| category |
|---|
| @Integrations |
useCookies
Wrapper for universal-cookie.
::: tip
When using with Nuxt 3, this functions will NOT be auto imported in favor of Nuxt's built-in useCookie(). Use explicit import if you want to use the function from VueUse.
:::
Install
npm i universal-cookie@^7
Usage
Common usage
<script setup lang="ts">
import { useCookies } from '@vueuse/integrations/useCookies'
const cookies = useCookies(['locale'])
</script>
<template>
<div>
<strong>locale</strong>: {{ cookies.get('locale') }}
<hr>
<pre>{{ cookies.getAll() }}</pre>
<button @click="cookies.set('locale', 'ru-RU')">
Russian
</button>
<button @click="cookies.set('locale', 'en-US')">
English
</button>
</div>
</template>
Options
Access and modify cookies using vue composition-api.
By default, you should use it inside
setup(), but this function also works anywhere else.
import { useCookies } from '@vueuse/integrations/useCookies'
// ---cut---
const {
get,
getAll,
set,
remove,
addChangeListener,
removeChangeListener
} = useCookies(['cookie-name'], {
doNotParse: false,
autoUpdateDependencies: false
})
dependencies (optional)
Let you optionally specify a list of cookie names your component depend on or that should trigger a re-render. If unspecified, it will render on every cookie change.
options (optional)
doNotParse(boolean = false): do not convert the cookie into an object no matter what. Passed as default value toget/getAllmethods.autoUpdateDependencies(boolean = false): automatically add cookie names ever provided togetmethod. If true then you don't need to care about provideddependencies.
cookies (optional)
Let you provide a universal-cookie instance (creates a new instance by default)
Info about methods available in the universal-cookie api docs
createCookies([req])
Create a universal-cookie instance using request (default is window.document.cookie) and returns useCookies function with provided universal-cookie instance
- req (object): Node's http.IncomingMessage request object
Type Declarations
/**
* Creates a new {@link useCookies} function
* @param req - incoming http request (for SSR)
* @see https://github.com/reactivestack/cookies/tree/master/packages/universal-cookie universal-cookie
* @description Creates universal-cookie instance using request (default is window.document.cookie) and returns {@link useCookies} function with provided universal-cookie instance
*/
export declare function createCookies(req?: IncomingMessage): (
dependencies?: string[] | null,
{
doNotParse,
autoUpdateDependencies,
}?: {
doNotParse?: boolean | undefined
autoUpdateDependencies?: boolean | undefined
},
) => {
/**
* Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
*/
get: <T = any>(name: string, options?: CookieGetOptions | undefined) => T
/**
* Reactive get all cookies
*/
getAll: <T = any>(options?: CookieGetOptions | undefined) => T
set: (
name: string,
value: any,
options?: CookieSetOptions | undefined,
) => void
remove: (name: string, options?: CookieSetOptions | undefined) => void
addChangeListener: (callback: CookieChangeListener) => void
removeChangeListener: (callback: CookieChangeListener) => void
}
/**
* Reactive methods to work with cookies (use {@link createCookies} method instead if you are using SSR)
* @param dependencies - array of watching cookie's names. Pass empty array if don't want to watch cookies changes.
* @param options
* @param options.doNotParse - don't try parse value as JSON
* @param options.autoUpdateDependencies - automatically update watching dependencies
* @param cookies - universal-cookie instance
*
* @__NO_SIDE_EFFECTS__
*/
export declare function useCookies(
dependencies?: string[] | null,
{
doNotParse,
autoUpdateDependencies,
}?: {
doNotParse?: boolean | undefined
autoUpdateDependencies?: boolean | undefined
},
cookies?: Cookie,
): {
/**
* Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
*/
get: <T = any>(name: string, options?: CookieGetOptions | undefined) => T
/**
* Reactive get all cookies
*/
getAll: <T = any>(options?: CookieGetOptions | undefined) => T
set: (
name: string,
value: any,
options?: CookieSetOptions | undefined,
) => void
remove: (name: string, options?: CookieSetOptions | undefined) => void
addChangeListener: (callback: CookieChangeListener) => void
removeChangeListener: (callback: CookieChangeListener) => void
}