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

通州建设网站个人怎么做免费百度推广

通州建设网站,个人怎么做免费百度推广,天津建设工程信息网公布,wordpress安装php需求 页面中上面搜索项有获取字典枚举接口,table表格中也有根据key匹配字典中的value 方案一 需要做到的要求 这里上面下拉列表是一个组件获取的字典,下面也是通过字典匹配,所以尽量统一封装一个函数,每个组件保证最少变动tabl…

需求

页面中上面搜索项有获取字典枚举接口,table表格中也有根据key匹配字典中的value

方案一

在这里插入图片描述

需要做到的要求

  • 这里上面下拉列表是一个组件获取的字典,下面也是通过字典匹配,所以尽量统一封装一个函数,每个组件保证最少变动
  • table表格中如果filters中更改,会获取多次接口,—使用闭包让只获取一次接口,节省性能
  • filter中又是必须同步函数,异步函数报错,所以不能使用async,await
  • 最好请求接口之后存储起来下次直接拿不用请求了

综上

utils/dictionary.js

import { getDicValue } from '@/api/systemManage'
import store from '@/store'
/*** 获取字典数据* @param {Boolean} hasAllOption 是否包含全部选项*/
export function getDicValueList(dictClassCode, hasAllOption = true) {const dictionaryCache = store.state.dictionary.dictionaryCache || {}return new Promise((resolve, reject) => {let optionList = []if (dictionaryCache[dictClassCode]) {const dicList = JSON.parse(JSON.stringify(dictionaryCache[dictClassCode]))if (hasAllOption) {optionList = [ { value: '', label: '全部' }, ...dicList]} else {optionList = [...dicList]}resolve(optionList)} else {getDicValue(dictClassCode).then(response => {console.log('字典调用', dictClassCode)const dicList = response.value || []store.dispatch('dictionary/setDictionaryCache', { key: dictClassCode, value: dicList })if (hasAllOption) {optionList = [ { value: '', label: '全部' }, ...dicList]} else {optionList = [...dicList]}resolve(optionList)}).catch(error => {reject([])})}})
}/*** 获取字典数据并返回一个闭包函数* @param {string} dictClassCode 字典类代码* @param {string} noTitle 默认值,当找不到匹配项时返回* @returns {Promise<Function>} 返回一个闭包函数,该函数可以根据 value 获取 label*/
export async function getDicValueName(dictClassCode, noTitle = "--") {try {const response = await getDicValueList(dictClassCode, false)const listData = response || []return (value) => {let label = noTitlelistData.some(item => {if (item.value === value) {label = item.labelreturn true}})return label}} catch (err) {console.error(err)return (value) => noTitle}
}

下拉框组件

created () {this.getOptionLists()},getOptionLists() {if (this.dictClassCode) {getDicValueList(this.dictClassCode).then(res => {this.optionLists = res})} else {this.optionLists = this.options}},

table组件中

<span>{{ filterStateName(scope.row.state) }}</span>import { getDicValueName } from '@/utils/dictionary'created() {this.initDictionary()},methods: {
async initDictionary() {try {this.filterStateName = await getDicValueName('DC_DICTIONARY_STATE')} catch (error) {console.error('Failed to fetch dictionary:', error)this.filterStateName = (value) => '--'}},}

问题: 但是这种因为一进页面这两个组件都是去获取字典,所以还是从接口拿的数据,会调用两次接口

方案二(建议)

方案:接下来优化可以通过路由导航预加载,先获取字典之后,在加载页面
router.js

// 预加载字典
export function preloadDictionary(dictClassCodeList) {const pList = []dictClassCodeList.forEach(dictClassCode => {const p = getDicValueList(dictClassCode)pList.push(p)})return Promise.all(pList)
}// 预加载字典
router.beforeEach((to, from, next) => {if(to.meta && to.meta.dictClassCodeList&& to.meta.dictClassCodeList.length > 0) {preloadDictionary(to.meta.dictClassCodeList).then(res => {next()})} else {next()}
})

总结:其实这里都可以规定直接预加载字典,到页面直接使用加载后的字典,注册个全局filters就行,根本不用上面那些,先都记录上,后期根据需求灵活应用吧

http://www.dtcms.com/wzjs/70057.html

相关文章:

  • 长安网站优化seo技术推广
  • 优秀国外设计网站关键词调词平台费用
  • 网站建设好了怎么进行推广品牌线上推广方式
  • 湖南省住建厅官方网站建设干校百度推广售后服务电话
  • 香精马鞍山网站seo
  • 个人合法网站怎么做杭州网站设计
  • 加速网站的加速器搜索 引擎优化
  • 企业网站建设分析报告网络推广的方法你知道几个?
  • 背景素材搜索关键词优化服务
  • 搜索案例的网站中国网评中国网评
  • 广州网站建设信科网络上海百度
  • 免费科技泸州网站优化推广
  • 松江泗泾附近做网站十大免费无代码开发软件
  • 营销网站策划关键词搜索热度
  • 网页编辑面试知识百度优化怎么做
  • 学校网站建设制度兰州网络推广电话
  • 海外网站建设公司网络公司的推广
  • 购买网站服务器企业网络营销顾问
  • 网站开发主管待遇互联网推广方式有哪些
  • 焦作市网站建设科技什么是百度指数
  • 驻马店营销型网站建设爱站网关键词查询工具
  • 常州微信网站建设效果怎样把自己的产品放到网上销售
  • 手机网站弹出提示框外贸推广
  • wordpress自适应代码做seo需要投入的成本
  • 用糖做的网站推广营销app
  • 湖州做网站建设的公司免费影视软件靠什么赚钱
  • 网站建设与组织管理广州网站优化方式
  • 网站建设新零售写软文怎么接单子
  • 动态手机网站怎么做的seo报告
  • wordpress4.6下载重庆seo海洋qq