sessionstorage

Vuex 刷新后数据丢失问题 Typescript

匆匆过客 提交于 2019-12-05 20:34:19
问题描述:Vuex保存的数据在页面刷新后会全部丢失清除 问题解决方案:使用sessionstorage进行保存,在页面刷新时保存至sessionStorage,页面在加载时再进行填充 (另有vuex-persistedstate 插件可以解决这个问题,本人是使用typescript,使用‘vuex-module-decorators’注册vuex各module,不知如何使用该插件,就没有尝试过,想试试的可以去搜索,很多这方面文章) 在App.vue 中 import { UserModule } from '@/store/modules/user' export default { created() { //在页面加载时读取sessionStorage里的状态信息 if (sessionStorage.getItem('store')) { this.$store.replaceState( Object.assign( {}, this.$store.state, JSON.parse(sessionStorage.getItem('store')) ) ) } //在页面刷新时将vuex里的信息保存到sessionStorage里 window.addEventListener('beforeunload', () => { console.log('setstore')

sessionStorage in Firefox

可紊 提交于 2019-12-05 08:37:27
in firefox 9, when i do: var msg = sessionStorage.getItem("message"); The browser ask with the error: "Operation is not supported", firefox not implement the webStorage of html5? or this case is only for sessionStorage and not for localStorage?. Thx. Session storage is only available when you are serving your page from a server - you'll find that it doesn't work if you open the HTML page locally because there is no session. In the case of browsers that may not support session storage, you can test for the feature: if (window.sessionStorage) { ... 来源: https://stackoverflow.com/questions/8924387

Access web storage from server side - possible?

こ雲淡風輕ζ 提交于 2019-12-05 01:18:49
I've stored some strings in web storage (session and/or local), and am wondering if it is possible to check for such stored strings on page load or init on the server-side (asp.net c# in my case)... So, for example, I will know not to re-fetch data from the db and use what is already resident in the browser from the last page load. No, that's not possible. sessionStorage lives on the client. If you want to access it on the server you will have to write javascript that reads the value, puts it in a hidden field so that it is sent to the server. Or javascript that will read the value from the

Duplicate Tab copying sessionStorage in Chrome

喜欢而已 提交于 2019-12-05 00:38:00
When a tab is duplicated in Chrome, is sessionStorage also duplicated? I noticed that in IE it is not. In Chrome, Yes. And you've hit on an important distinction. The contents of sessionStorage is "copied" not "shared". Any changes made to sessionStorage after the tab is duplicated are not reflected in the other tab's sessionStorage . Yes, if you duplicate the tab, the sessionStorage data is also duplicated on the copied tab. 来源: https://stackoverflow.com/questions/21463696/duplicate-tab-copying-sessionstorage-in-chrome

Vue自定义指令完成按钮级别的权限判断

不打扰是莪最后的温柔 提交于 2019-12-04 23:45:11
权限指令,对按钮权限的控制 1.登录成功后,获取后台返回所有的按钮权限,存到sessionStorage中( 也可以存到vuex ) 2.在main.js中自定义指令 3.定义指令,如果用户含有此按钮权限,则在页面显示出来( v-has绑定进行逻辑判断 ) 登录成功后,获取后台返回所有的按钮权限,存到sessionStorage中 // 4.5获取当前登录用户角色权限列表 这个方法在登录中调用 roleUserInfo() { this.$ajax.get("/role/permissionlist").then(res => { sessionStorage.setItem("loginVal", JSON.stringify(res.data.data)); setTimeout(() => { window.location.reload(); }, 50); }); } 在main.js中 自定义指令 //inserted:被绑定元素插入父节点时调用 (仅保证父节点存在,但不一定已被插入文档中) //如果bind获取不到el.parentNode //试试把 bind 改为 inserted const has = Vue.directive("has", { inserted: function(el, binding) { console.log(binding,"w"

ReactDOM.renderToString sessionStorage is not defined, window is not defined

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an application with webpack configured as a module bundler and babel as my js compiler. all on a node engine. I stetted up that when I run npm run dev the following flow will happen: The webpack-dev-server.js will run. the file is the following: const Express = require('express'); const webpack = require('webpack'); const webpackConfig = require('./dev.config'); const compiler = webpack(webpackConfig); const host = 'localhost'; const port = 8080; const serverOptions = { contentBase: `http://${host}:${port}`, quiet: true, noInfo: true,

SessionStorage and json objects

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: user : { firstName : "lokesh" , lastName : "che" } I am storing this user in session storage. $window . sessionStorage . user = user ; when i retrieved it back using $window.sessionStorage.user , i got: [ object Object ] I want in JSON. Any suggestions? 回答1: Convert it to JSON before saving it. $window . sessionStorage . user = JSON . stringify ( user ); Then when you're loading it, parse the JSON. var user = JSON . parse ( $window . sessionStorage . user ); 转载请标明出处: SessionStorage and json objects 文章来源: SessionStorage and json

Using SharpArchitecture's NHibernateSession in conjunction with a different thread

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm using SharpArchitecture in an ASP.NET MVC 3 application. Everything works wonderfully. Using SharpArchitecture's NHibernateInitializer to initialize a new Session per request like so: protected void Application_BeginRequest ( object sender , EventArgs e ) { NHibernateInitializer . Instance (). InitializeNHibernateOnce ( InitializeNHibernateSession ); } private void InitializeNHibernateSession ( ISessionStorage sessionStorage ) { NHibernateSession . ConfigurationCache = new NHibernateConfigurationFileCache ( new [] { "App.Core"

axios 拦截以及 API简单配置(element)

南楼画角 提交于 2019-12-03 03:49:28
在某些情况下,有时候会在接口请求的API中需要拿到存在浏览器中的COOKIE,调用的方式可以为: // 获取浏览器Cookie function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } 在axios请求中,需要在发送前和发送后进行简单的设置拦截: // 添加一个响应拦截器 Axios.interceptors.request.use((config) => { let account = sessionStorage.account; let token = sessionStorage.token; // if(config.url == Axios.bullRanking){ /

vue实现原理

无人久伴 提交于 2019-12-03 02:36:37
Observer -通过Object.defineProperty包装为可订阅对象 Watcher 观察者模式,监听所有可订阅对象变化 Compile 将对指令、模板等进行解析 diff算法 同层比较,不会垮层级比较。深度优先 ==当数据发生改变时,set方法会让调用Dep.notify通知所有订阅者Watcher,订阅者就会调用patch给真实的DOM打补丁,更新相应的视图== diff算法同层操作 同层,此节点是否被移除=》添加新的节点 属性是否改变=》旧属性改为新属性 文本内容改变=》旧内容改为新内容 节点要被整个替换=》结构完全不相同,移除整个替换 patch算法 先根据真实DOM生成一颗virtual DOM,当virtual DOM某个节点的数据改变后会生成一个新的Vnode,然后Vnode和oldVnode作对比,发现有不一样的地方就直接修改在真实的DOM上,然后使oldVnode的值为Vnode diff的过程就是调用名为patch的函数,比较新旧节点,一边比较一边给真实的DOM打补丁 虚拟DOM:本质在JS和DOM之间做一个缓存 virtual DOM是将真实的DOM的数据抽取出来,以对象的形式模拟树形结构 用JS对象方式表示DOM树的结构,然后用这个树构建成一个真正的DOM树,插入到文档中 当状态变更的时候,重新构造一棵新的对象树,然后用新的树和旧的树进行比较(