代码拉取完成,页面将自动刷新
// 引入Cookies
import Cookies from 'js-cookie'
/**
* 时间戳
* @param {*} timestamp 时间戳
*/
const timestampToTime = (timestamp) => {
const date = new Date(timestamp) // 时间戳为10位需*1000,时间戳为13位的话不需乘1000
const Y = date.getFullYear() + '-'
const M =
(date.getMonth() + 1 < 10
? '0' + (date.getMonth() + 1)
: date.getMonth() + 1) + '-'
const D =
(date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
const h =
(date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
const m =
(date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
':'
const s =
date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return Y + M + D + h + m + s
}
/**
* 存储localStorage
*/
const setStore = (name, content) => {
if (!name) { return }
if (typeof content !== 'string') {
content = JSON.stringify(content)
}
window.localStorage.setItem(name, content)
}
/**
* 获取localStorage
*/
const getStore = (name) => {
if (!name) { return }
return window.localStorage.getItem(name)
}
/**
* 删除localStorage
*/
const removeStore = (name) => {
if (!name) { return }
window.localStorage.removeItem(name)
}
/**
* 设置cookie
**/
function setCookie (name, value, day) {
return Cookies.set(name, value, { expires: day })
}
/**
* 获取cookie
**/
function getCookie (name) {
return Cookies.get(name)
}
/**
* 删除cookie
**/
function delCookie (name) {
return Cookies.remove(name)
}
/**
* 导出
**/
export {
timestampToTime,
setStore,
getStore,
removeStore,
setCookie,
getCookie,
delCookie
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。