新建一个 util文件夾 ---> tool.jsx

window._= {
		/**
		 * 存储localStorage
		 */
		setStore:(name, content) =>{
			if (!name) return;
			if (typeof content !== 'string') {
				content = JSON.stringify(content);
			}
			window.localStorage.setItem(name, content);
		},
		/**
		 * 获取localStorage
		 */
		getStore:(name) => {
			if (!name) return;
			return window.localStorage.getItem(name);
		},
		/**
		 * 清除localStorage
		 */
		clearStore:() => {
			window.localStorage.clear();
		},
		
		getQueryStringByName: function (name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			var context = "";
			if (r != null)
				context = r[2];
			reg = null;
			r = null;
			return context == null || context == "" || context == "undefined" ? "" : context;
		}
	
}

在入口文件app.jsx里面引入

import  "util/tool.jsx";

 然后在其余的组件里面就可以访问到这个变量对象:_

 

Logo

Agent 垂直技术社区,欢迎活跃、内容共建,欢迎商务合作。wx: diudiu5555

更多推荐