当前位置: 首页 > news >正文

营销型网站策划建设企业网站搜索推广

营销型网站策划建设,企业网站搜索推广,263企业邮箱自动回复,网上如何推广产品正常来说#xff0c;一个vue项目前端需要用到的一些翻译字典对象保存方式一般有多重#xff0c; 新建js文件方式保存通过vuex方式保存通过sessionStorage保存通过localStorage保存 正常以上几点的保存方式是够用了。 但是#xff0c;当有字典不能以文件方式保存并且字典量…正常来说一个vue项目前端需要用到的一些翻译字典对象保存方式一般有多重 新建js文件方式保存通过vuex方式保存通过sessionStorage保存通过localStorage保存 正常以上几点的保存方式是够用了。 但是当有字典不能以文件方式保存并且字典量很多很大时候要考虑的事情就多了。 首选最新考虑存储的地方是vuex跟session安全性会相对高一些其次就需要考虑如果量大的问题。当字典数据量超过5MB的话那session就有些难受了。而vuex持久存储也是需要先存Storage中再取回到内存中用。那么怎么比较好解决这个量大且不能以文件存储方式呢。 思路 字典都是从后端调接口获取 还是通过session方式储存额外有的看需求要不要再存储到vuex中给session增加存储过期时间给session增加存储量是否接近5MB存储上限判断字典通过后端调接口获取 4.1 获取地方 1.通过路由跳转时beforeRouteEnter回调中调用跟判断 4.2 获取地方 2.通过页面created 回调中调用跟判断(有的是弹框子组件或者form表单并没有进行路由跳转)由于基本每个菜单页面都要使用到字典所以考虑通过混入mixin方式#由于字典一般用于选项跟翻译所以需要考虑是否使用 async/await方式来同步代码确保字典数据先取到再进入页面。是否使用各有利弊。 混入代码 window.g.SESSION_TIMEOUT 是定义全局变量可配置DICE_KEYS 是存储字典key的数组SESSION_TIMEOUT 为字典过期时间 export default function (dictKeys []) {let _isBeforeRouteEnterDictQuery falsereturn {data() {return {m_dictsFin: false,m_dicts: {}}},provide: function () {return {m_dicts: this.m_dicts}},methods: {getSessionStorageSize(){let obj let size 0if(!window.sessionStorage){try {throw Error(浏览器不支持sessionStorage)} catch (error) {console.log(error)}}else {obj window.sessionStorage}if(obj ! ){for(item in obj){if(obj.hasOwnProperty(item)){size obj.getItem(item).length}}}let val (size/1024).toFixed(2) //单位KB 5MB 1024*5 5120kB// 1024 * 4.5 4608if(val 4608){ //如果存储大小超过4.5MB则需清空KEY重新获取过return true}else {return false}},//如果上面一个获取方法不可用可以考虑使用这个方法替换estimateSessionStorageSize() {let totalSize 0;// 遍历 sessionStorage 中的每个项for (let i 0; i sessionStorage.length; i) {const key sessionStorage.key(i)const value sessionStorage.getItem(key)// 估算每个项的大小这里简单估算每个字符占2个字节// 注意这只是一个非常粗略的估算const size (new Blob([key value])).size// 累加大小totalSize size}let val (totalSize/1024).toFixed(2) //单位KB 5MB 1024*5 5120kB// 1024 * 4.5 4608if(val 4608){ //如果存储大小超过4.5MB则需清空KEY重新获取过return true}else {return false}},setPageConfig(res,vm){const list res?.data?.data || []store.dispatch(dynamicDicts, list)const pathAllDict {}if (list list.length 0) {const sessionName []list.forEach(e {if (e) {if(vm){vm.$set(vm.m_dicts, e.dictCode, e.dictDatas)}else {this.$set(this.m_dicts, e.dictCode, e.dictDatas)}sessionName.push(e.dictCode)pathAllDict[e.dictCode] e.dictDatassessionStorage.setItem(e.dictCode, JSON.stringify(e.dictDatas))}})store.commit(SET_DICT_DATA, pathAllDict)let currentSessionKey sessionStorage.getItem(DICE_KEYS) ? sessionStorage.getItem(DICE_KEYS).split(,) : []console.log(setPageConfig,currentSessionKey,sessionName)console.log(DICE_KEYS,[...new Set([...currentSessionKey,...sessionName])])sessionStorage.setItem(DICE_KEYS, [...new Set([...currentSessionKey,...sessionName])])if(vm){vm.$nextTick(() {vm.m_dictsFin true})}else {this.m_dictsFin true}}}},beforeRouteEnter(to, from, next) {_isBeforeRouteEnterDictQuery truenext(async vm {const date new Date().getTime()let DICE_KEYS sessionStorage.getItem(DICE_KEYS) || []if(!DICE_KEYS || DICE_KEYS.length 0){ //没存字典或者已全删除//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {vm.setPageConfig(res,vm)}).catch(e {console.log(catch)next()})}}else {//获取过期时间let timeout sessionStorage.getItem(SESSION_TIMEOUT)const preSessionS DICE_KEYS.length0 ? DICE_KEYS.split(,) : [] //转为数组if(vm.getSessionStorageSize()){preSessionS.forEach(item {sessionStorage.removeItem(item)//清除所有字典})sessionStorage.setItem(DICE_KEYS,[])//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {vm.setPageConfig(res,vm)}).catch(e {console.log(catch)next()})}}else {if(timeout){if(timeout - date 0){ //已过期preSessionS.forEach(item {sessionStorage.removeItem(item)//清除所有字典})sessionStorage.setItem(DICE_KEYS,[])//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {vm.setPageConfig(res,vm)}).catch(e {console.log(catch)next()})}} else {//将已存在于session重的key挂载到m_dicts对象重let sessionKeyList dictKeys.filter(item preSessionS.includes(item))sessionKeyList.forEach(e {if (e) {vm.$set(vm.m_dicts, e, JSON.parse(sessionStorage.getItem(e)))}})//当前dictKeys匹配session中不存在的key去请求let reqKeyList dictKeys.filter(item !preSessionS.includes(item))if(reqKeyList.length 0){await queryBatchCode(reqKeyList, { isNoLoading: true }).then(res {vm.setPageConfig(res,vm)}).catch(e {console.log(catch)next()})}}}else {//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {vm.setPageConfig(res,vm)}).catch(e {console.log(catch)next()})}}}}})},// 有些非路由跳转触发的组件, 在 created 中调用async created() {if (_isBeforeRouteEnterDictQuery) returnif (!this.m_dictsFin) {const date new Date().getTime()let DICE_KEYS sessionStorage.getItem(DICE_KEYS) || []if(!DICE_KEYS || DICE_KEYS.length 0){ //没存字典或者已全删除//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {this.setPageConfig(res)})}}else {//获取过期时间let timeout sessionStorage.getItem(SESSION_TIMEOUT)const preSessionS DICE_KEYS.length0 ? DICE_KEYS.split(,) : [] //转为数组if(this.getSessionStorageSize()){preSessionS.forEach(item {sessionStorage.removeItem(item)//清除所有字典})sessionStorage.setItem(DICE_KEYS,[])//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {this.setPageConfig(res)})}}else {if(timeout){if(timeout - date 0){ //已过期preSessionS.forEach(item {sessionStorage.removeItem(item)//清除所有字典})sessionStorage.setItem(DICE_KEYS,[])//重新设置过期时间let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {this.setPageConfig(res)})}} else {//将已存在于session重的key挂载到m_dicts对象重let sessionKeyList dictKeys.filter(item preSessionS.includes(item))sessionKeyList.forEach(e {if (e) {this.$set(this.m_dicts, e, JSON.parse(sessionStorage.getItem(e)))}})//当前dictKeys匹配session中不存在的key去请求let reqKeyList dictKeys.filter(item !preSessionS.includes(item))if(reqKeyList.length 0){await queryBatchCode(reqKeyList, { isNoLoading: true }).then(res {this.setPageConfig(res)})}}}else {let timing date 1000 * 60 * window.g.SESSION_TIMEOUTsessionStorage.setItem(SESSION_TIMEOUT, timing)//调用接口if(dictKeys dictKeys.length 0){await queryBatchCode(dictKeys, { isNoLoading: true }).then(res {this.setPageConfig(res)})}}}}}}} }在具体页面中使用 import pageDictMixin from /mixin/page-dict-mixinmixins: [pageDictMixin([DICT_YES_NO])],html部分代码 el-optionv-foritem in m_dicts.DICT_YES_NO :keyitem.dataValue:labelitem.dataLabel :valueitem.dataValue /
http://www.w-s-a.com/news/967788/

相关文章:

  • 网站建设哪个公司最好shift wordpress
  • 公司网站建设功能介绍室内设计学习
  • 做网站策划容易遇到哪些问题沈阳公司网站制作
  • 做php网站都用框架吗网站备案当面核验拍摄照片
  • 泉州企业自助建站兰州最好的互联网公司
  • 监察部门网站建设方案网站seo技术教程
  • 个人网站制作源代码下载品牌建设部
  • 网站备案需要准备什么文创产品设计思路
  • 网站开发书籍推荐青岛城阳新闻最新消息
  • 秦皇岛网站建设服务聊城做网站的公司资讯
  • 30岁转行做网站设计丰涵网站建设
  • 山东省和住房建设厅网站首页开发商不按时交房可以退房吗
  • asp网站怎么做404页面跳转本地南通网站建设
  • 点击网站出现微信二维码的链接怎么做申请网站空间怎么做
  • 网站开发的论文题目广告设计排行榜
  • 网络营销网站 功能南京h5制作公司
  • 做网站的费用的会计分录合肥做网站推广哪家好
  • 电子商城网站开发怎么wordpress用的什么主题
  • 榆林电商网站建设网上做试卷的网站
  • 文山网站建设代理中公教育培训机构官网
  • 郑州it培训机构有哪些上海外贸网站seo
  • dw做网站的实用特效广东住房与城乡建设厅网站
  • 模板网站 动易哪方面的网站
  • 怎么给网站做外链邵连虎郑州做网页的公司
  • 重庆网站开发哪家好宁波网站建设caiyiduo
  • 手机网站建设价格手机网站模版更换技巧
  • 哈尔滨松北区建设局网站美妆网站建设
  • 不需要网站备案的空间网站推广的基本方法是哪四个
  • 如何检查网站死链劳动仲裁院内部网站建设
  • 江西省住房和城乡建设网站合同管理系统