当前位置 : 主页 > 网络编程 > JavaScript >

localStorage

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt /** * 存储localStorage */export const setStore = (name, content) = {if (!name) return;if (typeof content !== 'string') {content = JSON.stringify(content);}window.localStorage.setItem(name, content);}/** * 获取localStorage
gistfile1.txt
/**
 * 存储localStorage
 */
export const setStore = (name, content) => {
	if (!name) return;
	if (typeof content !== 'string') {
		content = JSON.stringify(content);
	}
	window.localStorage.setItem(name, content);
}

/**
 * 获取localStorage
 */
export const getStore = name => {
	if (!name) return;
	return window.localStorage.getItem(name);
}

/**
 * 删除localStorage
 */
export const removeStore = name => {
	if (!name) return;
	window.localStorage.removeItem(name);
}
网友评论