Vue高级特性实战:自定义指令、插槽与路由全解析

一、自定义指令

1.如何自定义指令

⑴.全局注册语法

通过 Vue.directive 方法注册,语法格式为:

Vue.directive('指令名', {// 钩子函数,元素插入父节点时触发(仅保证父节点存在,不一定已插入文档)inserted(el) { // el 表示绑定指令的 DOM 元素,可在此进行 DOM 操作el.focus(); // 示例:让元素获取焦点}// 其他钩子函数(如 bind、update 等,可选)
})
  • 参数说明
    • '指令名':指令的名称,使用时以 v- 前缀调用(如 v-focus)。
    • inserted:钩子函数,当元素插入父节点时触发(仅保证父节点存在,不一定已插入文档),常用于初始化 DOM 操作。
    • el:绑定指令的 DOM 元素,可直接操作该元素。

示例

// 全局注册一个自动获取焦点的指令 v-focus
Vue.directive('focus', {inserted(el) {el.focus(); // 元素插入时获取焦点}
})// 使用方式:<input v-focus type="text">

main.js

import { createApp } from 'vue';
import App from './App.vue';// 创建 Vue 应用实例
const app = createApp(App);// 全局注册自定义指令 v-focus
app.directive('focus', {inserted(el) {el.focus();}
});// 挂载应用
app.mount('#app');

App.vue

<template><div><h1>自定义指令</h1><input v-focus ref="inp" type="text"></div>
</template><script>
export default {// 移除局部注册的指令
}
</script><style></style>

⑵.局部注册语法

在组件内部通过 directives 选项注册,仅在当前组件内生效,语法格式为:

export default {directives: {// 指令名(无需 v- 前缀,注册名与使用名一致)指令名: { inserted(el) {// 操作 DOMel.focus(); // 示例:让元素获取焦点}}}
}
  • 参数说明
    • directives:组件选项,用于声明局部自定义指令。
    • 指令名:注册的指令名称,使用时以 v- 前缀调用(如 v-focus)。
    • inserted 钩子及 el 参数含义与全局注册一致。

示例

<template><input v-focus type="text"> <!-- 使用指令 -->
</template><script>
export default {directives: {// 局部注册 v-focus 指令focus: { inserted(el) {el.focus(); // 元素插入时获取焦点}}}
}
</script>

App.vue

<template><div><h1>自定义指令</h1><input v-focus ref="inp" type="text"></div>
</template><script>
export default {// 局部注册指令directives: {// 指令名:指令的配置项focus: {inserted (el) {// 当元素插入到 DOM 中时,让元素获取焦点el.focus()}}}
}
</script><style></style>    

两种注册方式的区别

  • 全局注册:通过 Vue.directive 注册后,所有组件均可使用该指令,适用于通用功能(如全局的焦点控制、权限校验等)。
  • 局部注册:通过组件内的 directives 选项注册,仅当前组件可用,适用于特定组件的特殊 DOM 操作,避免污染全局作用域。

通过自定义指令,可封装重复的 DOM 操作逻辑,提升代码复用性与简洁性。


2.自定义指令 - 指令的值

<template><div><h1 v-color="color1">指令的值1测试</h1><h1 v-color="color2">指令的值2测试</h1></div>
</template><script>
export default {data () {return {color1: 'red',color2: 'orange'}},directives: {color: {// 1. inserted 提供的是元素被添加到页面中时的逻辑inserted (el, binding) {console.log(el, binding.value);// binding.value 就是指令的值el.style.color = binding.value},// 2. update 指令的值修改的时候触发,提供值变化后,dom更新的逻辑update (el, binding) {console.log('指令的值修改了');el.style.color = binding.value}}}
}
</script><style></style>

3.自定义指令 - v-loading 指令封装


App.vue

<template><div class="main"><div class="box" v-loading="isLoading"><ul><li v-for="item in list" :key="item.id" class="news"><div class="left"><div class="title">{{ item.title }}</div><div class="info"><span>{{ item.source }}</span><span>{{ item.time }}</span></div></div><div class="right"><img :src="item.img" alt=""></div></li></ul></div><div class="box2" v-loading="isLoading2"></div></div>
</template><script>
// 安装axios =>  yarn add axios
import axios from 'axios'// 接口地址:http://hmajax.itheima.net/api/news
// 请求方式:get
export default {data () {return {list: [],isLoading: true,isLoading2: true}},async created () {// 1. 发送请求获取数据const res = await axios.get('http://hmajax.itheima.net/api/news')setTimeout(() => {// 2. 更新到 list 中,用于页面渲染 v-forthis.list = res.data.datathis.isLoading = false}, 2000)},directives: {loading: {inserted (el, binding) {binding.value ? el.classList.add('loading') : el.classList.remove('loading')},update (el, binding) {binding.value ? el.classList.add('loading') : el.classList.remove('loading')}}}
}
</script><style>
.loading:before {content: '';position: absolute;left: 0;top: 0;width: 100%;height: 100%;background: #fff url('./loading.gif') no-repeat center;
}.box2 {width: 400px;height: 400px;border: 2px solid #000;position: relative;
}.box {width: 800px;min-height: 500px;border: 3px solid orange;border-radius: 5px;position: relative;
}
.news {display: flex;height: 120px;width: 600px;margin: 0 auto;padding: 20px 0;cursor: pointer;
}
.news .left {flex: 1;display: flex;flex-direction: column;justify-content: space-between;padding-right: 10px;
}
.news .left .title {font-size: 20px;
}
.news .left .info {color: #999999;
}
.news .left .info span {margin-right: 20px;
}
.news .right {width: 160px;height: 120px;
}
.news .right img {width: 100%;height: 100%;object-fit: cover;
}
</style>

二、插槽

1.插槽 - 默认插槽

插槽(Slots)是 Vue 实现组件内容分发的机制,允许我们在组件模板中预留一个或多个区域,将不同的内容插入到这些区域中。它就像是组件模板中的 “占位符”,可以让父组件决定子组件的部分内容如何展示。这大大增强了组件的复用性和灵活性,使得同一个组件可以根据不同的使用场景展示不同的内容。


MyDialog.vue

<template><div class="dialog"><div class="dialog-header"><h3>友情提示</h3><span class="close">✖️</span></div><div class="dialog-content"><!-- 1. 在需要定制的位置,使用slot占位 --><slot></slot></div><div class="dialog-footer"><button>取消</button><button>确认</button></div></div>
</template><script>
export default {data () {return {}}
}
</script><style scoped>
* {margin: 0;padding: 0;
}
.dialog {width: 470px;height: 230px;padding: 0 25px;background-color: #ffffff;margin: 40px auto;border-radius: 5px;
}
.dialog-header {height: 70px;line-height: 70px;font-size: 20px;border-bottom: 1px solid #ccc;position: relative;
}
.dialog-header .close {position: absolute;right: 0px;top: 0px;cursor: pointer;
}
.dialog-content {height: 80px;font-size: 18px;padding: 15px 0;
}
.dialog-footer {display: flex;justify-content: flex-end;
}
.dialog-footer button {width: 65px;height: 35px;background-color: #ffffff;border: 1px solid #e1e3e9;cursor: pointer;outline: none;margin-left: 10px;border-radius: 3px;
}
.dialog-footer button:last-child {background-color: #007acc;color: #fff;
}
</style>

App.vue

<template><div><!-- 2. 在使用组件时,组件标签内填入内容 --><MyDialog><div>你确认要删除么</div></MyDialog><MyDialog><p>你确认要退出么</p><p>你确认要退出么</p><p>你确认要退出么</p></MyDialog></div>
</template><script>
import MyDialog from './components/MyDialog.vue'
export default {data () {return {}},components: {MyDialog}
}
</script><style>
body {background-color: #b3b3b3;
}
</style>

2.插槽 - 后备内容(默认值)


MyDialog.vue

<template><div class="dialog"><div class="dialog-header"><h3>友情提示</h3><span class="close">✖️</span></div><div class="dialog-content"><!-- 往slot标签内部,编写内容,可以作为后备内容(默认值) --><slot>我是默认的文本内容</slot></div><div class="dialog-footer"><button>取消</button><button>确认</button></div></div>
</template><script>
export default {data () {return {}}
}
</script><style scoped>
* {margin: 0;padding: 0;
}
.dialog {width: 470px;height: 230px;padding: 0 25px;background-color: #ffffff;margin: 40px auto;border-radius: 5px;
}
.dialog-header {height: 70px;line-height: 70px;font-size: 20px;border-bottom: 1px solid #ccc;position: relative;
}
.dialog-header .close {position: absolute;right: 0px;top: 0px;cursor: pointer;
}
.dialog-content {height: 80px;font-size: 18px;padding: 15px 0;
}
.dialog-footer {display: flex;justify-content: flex-end;
}
.dialog-footer button {width: 65px;height: 35px;background-color: #ffffff;border: 1px solid #e1e3e9;cursor: pointer;outline: none;margin-left: 10px;border-radius: 3px;
}
.dialog-footer button:last-child {background-color: #007acc;color: #fff;
}
</style>

App.vue

<template><div><MyDialog></MyDialog><MyDialog>你确认要退出么</MyDialog></div>
</template><script>
import MyDialog from './components/MyDialog.vue'
export default {data () {return {}},components: {MyDialog}
}
</script><style>
body {background-color: #b3b3b3;
}
</style>

3.插槽 - 具名插槽


MyDialog.vue

<template><div class="dialog"><div class="dialog-header"><!-- 一旦插槽起了名字,就是具名插槽,只支持定向分发 --><slot name="head"></slot></div><div class="dialog-content"><slot name="content"></slot></div><div class="dialog-footer"><slot name="footer"></slot></div></div>
</template><script>
export default {data () {return {}}
}
</script><style scoped>
* {margin: 0;padding: 0;
}
.dialog {width: 470px;height: 230px;padding: 0 25px;background-color: #ffffff;margin: 40px auto;border-radius: 5px;
}
.dialog-header {height: 70px;line-height: 70px;font-size: 20px;border-bottom: 1px solid #ccc;position: relative;
}
.dialog-header .close {position: absolute;right: 0px;top: 0px;cursor: pointer;
}
.dialog-content {height: 80px;font-size: 18px;padding: 15px 0;
}
.dialog-footer {display: flex;justify-content: flex-end;
}
.dialog-footer button {width: 65px;height: 35px;background-color: #ffffff;border: 1px solid #e1e3e9;cursor: pointer;outline: none;margin-left: 10px;border-radius: 3px;
}
.dialog-footer button:last-child {background-color: #007acc;color: #fff;
}
</style>

App.vue

<template><div><MyDialog><!-- 需要通过template标签包裹需要分发的结构,包成一个整体 --><template v-slot:head><div>我是大标题</div></template><template v-slot:content><div>我是内容</div></template><template #footer><button>取消</button><button>确认</button></template></MyDialog></div>
</template><script>
import MyDialog from './components/MyDialog.vue'
export default {data () {return {}},components: {MyDialog}
}
</script><style>
body {background-color: #b3b3b3;
}
</style>

4.插槽 - 作用域插槽


App.vue

<template><div><MyTable :data="list"><!-- 3. 通过template #插槽名="变量名" 接收 --><template #default="obj"><button @click="del(obj.row.id)">删除</button></template></MyTable><MyTable :data="list2"><template #default="{ row }"><button @click="show(row)">查看</button></template></MyTable></div>
</template><script>
import MyTable from './components/MyTable.vue'
export default {data () {return {list: [{ id: 1, name: '张小花', age: 18 },{ id: 2, name: '孙大明', age: 19 },{ id: 3, name: '刘德忠', age: 17 },],list2: [{ id: 1, name: '赵小云', age: 18 },{ id: 2, name: '刘蓓蓓', age: 19 },{ id: 3, name: '姜肖泰', age: 17 },]}},methods: {del (id) {this.list = this.list.filter(item => item.id !== id)},show (row) {// console.log(row);alert(`姓名:${row.name}; 年纪:${row.age}`)}},components: {MyTable}
}
</script>

MyTable.vue

<template><table class="my-table"><thead><tr><th>序号</th><th>姓名</th><th>年纪</th><th>操作</th></tr></thead><tbody><tr v-for="(item, index) in data" :key="item.id"><td>{{ index + 1 }}</td><td>{{ item.name }}</td><td>{{ item.age }}</td><td><!-- 1. 给slot标签,添加属性的方式传值 --><slot :row="item" msg="测试文本"></slot><!-- 2. 将所有的属性,添加到一个对象中 --><!-- {row: { id: 2, name: '孙大明', age: 19 },msg: '测试文本'}--></td></tr></tbody></table>
</template><script>
export default {props: {data: Array}
}
</script><style scoped>
.my-table {width: 450px;text-align: center;border: 1px solid #ccc;font-size: 24px;margin: 30px auto;
}
.my-table thead {background-color: #1f74ff;color: #fff;
}
.my-table thead th {font-weight: normal;
}
.my-table thead tr {line-height: 40px;
}
.my-table th,
.my-table td {border-bottom: 1px solid #ccc;border-right: 1px solid #ccc;
}
.my-table td:last-child {border-right: none;
}
.my-table tr:last-child td {border-bottom: none;
}
.my-table button {width: 65px;height: 35px;font-size: 18px;border: 1px solid #ccc;outline: none;border-radius: 3px;cursor: pointer;background-color: #ffffff;margin-left: 5px;
}
</style>

运行结果:

:data="list" 和 :data="list2" 的作用

  • MyTable 组件MyTable 组件有一个名为 data 的 props,其类型为数组,用于接收外部传入的数据。
export default {props: {data: Array}
}
  • 父组件的数据:父组件里定义了两个数组 list 和 list2,它们各自包含了不同的数据项。
data () {return {list: [{ id: 1, name: '张小花', age: 18 },{ id: 2, name: '孙大明', age: 19 },{ id: 3, name: '刘德忠', age: 17 },],list2: [{ id: 1, name: '赵小云', age: 18 },{ id: 2, name: '刘蓓蓓', age: 19 },{ id: 3, name: '姜肖泰', age: 17 },]}
}
  • 属性绑定
    • :data="list":把父组件的 list 数组传递给 MyTable 组件的 data 属性。这样,MyTable 组件就能使用 list 数组里的数据进行渲染。
    • :data="list2":把父组件的 list2 数组传递给另一个 MyTable 组件的 data 属性。这个 MyTable 组件会使用 list2 数组里的数据进行渲染。

在 Vue 组件中,<slot :row="item" msg="测试文本"></slot> 涉及 插槽传值,用于向父组件使用插槽的区域传递数据,具体解释如下:

1. :row="item"(动态属性绑定传值)

  • 作用:通过动态绑定(v-bind: 缩写 :),将子组件当前循环的 item 数据(如 { id: 1, name: '张小花', age: 18 })作为名为 row 的属性传递给父组件的插槽。
  • 父组件接收:父组件通过 template #default="obj"(或简化为 template #default="{ row }")接收,obj 或 row 即可获取子组件传递的 item 数据。例如:
    • <template #default="obj"> 中,obj.row 即子组件传递的 item
    • <template #default="{ row }"> 是解构赋值,直接通过 row 访问 item

2. msg="测试文本"(普通属性传值)

  • 作用:通过普通属性,将字符串 测试文本 作为名为 msg 的属性传递给父组件的插槽。
  • 父组件接收:父组件在插槽作用域内可通过 obj.msg(若按 template #default="obj" 接收)获取该值。例如:
<template #default="obj"><span>{{ obj.msg }}</span> <!-- 显示 "测试文本" -->
</template>

三、综合案例:商品列表

MyTable.vue

<template><table class="my-table"><thead><tr><slot name="head"></slot></tr></thead><tbody><tr v-for="(item, index) in data" :key="item.id"><slot name="body" :item="item" :index="index" ></slot></tr></tbody></table>
</template><script>
export default {props: {data: {type: Array,required: true}}
};
</script><style lang="less" scoped>.my-table {width: 100%;border-spacing: 0;img {width: 100px;height: 100px;object-fit: contain;vertical-align: middle;}th {background: #f5f5f5;border-bottom: 2px solid #069;}td {border-bottom: 1px dashed #ccc;}td,th {text-align: center;padding: 10px;transition: all .5s;&.red {color: red;}}.none {height: 100px;line-height: 100px;color: #999;}
}</style>

MyTag.vue

<template><div class="my-tag"><inputv-if="isEdit"v-focusref="inp"class="input"type="text"placeholder="输入标签":value="value"@blur="isEdit = false"@keyup.enter="handleEnter"/><div v-else@dblclick="handleClick"class="text">{{ value }}</div></div>
</template><script>
export default {props: {value: String},data () {return {isEdit: false}},methods: {handleClick () {// 双击后,切换到显示状态 (Vue是异步dom更新)this.isEdit = true// // 等dom更新完了,再获取焦点// this.$nextTick(() => {//   // 立刻获取焦点//   this.$refs.inp.focus()// })},handleEnter (e) {// 非空处理if (e.target.value.trim() === '') return alert('标签内容不能为空')// 子传父,将回车时,[输入框的内容] 提交给父组件更新// 由于父组件是v-model,触发事件,需要触发 input 事件this.$emit('input', e.target.value)// 提交完成,关闭输入状态this.isEdit = false}}
}
</script><style lang="less" scoped>
.my-tag {cursor: pointer;.input {appearance: none;outline: none;border: 1px solid #ccc;width: 100px;height: 40px;box-sizing: border-box;padding: 10px;color: #666;&::placeholder {color: #666;}}
}
</style>

App.vue

<template><div class="table-case"><MyTable :data="goods"><template #head><th>编号</th><th>名称</th><th>图片</th><th width="100px">标签</th></template><template #body="{ item, index }"><td>{{ index + 1 }}</td><td>{{ item.name }}</td><td><img:src="item.picture"/></td><td><MyTag v-model="item.tag"></MyTag></td></template></MyTable></div>
</template><script>
// my-tag 标签组件的封装
// 1. 创建组件 - 初始化
// 2. 实现功能
//    (1) 双击显示,并且自动聚焦
//        v-if v-else @dbclick 操作 isEdit
//        自动聚焦:
//        1. $nextTick => $refs 获取到dom,进行focus获取焦点
//        2. 封装v-focus指令//    (2) 失去焦点,隐藏输入框
//        @blur 操作 isEdit 即可//    (3) 回显标签信息
//        回显的标签信息是父组件传递过来的
//        v-model实现功能 (简化代码)  v-model => :value 和 @input
//        组件内部通过props接收, :value设置给输入框//    (4) 内容修改了,回车 => 修改标签信息
//        @keyup.enter, 触发事件 $emit('input', e.target.value)// ---------------------------------------------------------------------// my-table 表格组件的封装
// 1. 数据不能写死,动态传递表格渲染的数据  props
// 2. 结构不能写死 - 多处结构自定义 【具名插槽】
//    (1) 表头支持自定义
//    (2) 主体支持自定义import MyTag from './components/MyTag.vue'
import MyTable from './components/MyTable.vue'
export default {name: 'TableCase',components: {MyTag,MyTable},data () {return {// 测试组件功能的临时数据tempText: '水杯',tempText2: '钢笔',goods: [{ id: 101, picture: 'https://yanxuan-item.nosdn.127.net/f8c37ffa41ab1eb84bff499e1f6acfc7.jpg', name: '梨皮朱泥三绝清代小品壶经典款紫砂壶', tag: '茶具' },{ id: 102, picture: 'https://yanxuan-item.nosdn.127.net/221317c85274a188174352474b859d7b.jpg', name: '全防水HABU旋钮牛皮户外徒步鞋山宁泰抗菌', tag: '男鞋' },{ id: 103, picture: 'https://yanxuan-item.nosdn.127.net/cd4b840751ef4f7505c85004f0bebcb5.png', name: '毛茸茸小熊出没,儿童羊羔绒背心73-90cm', tag: '儿童服饰' },{ id: 104, picture: 'https://yanxuan-item.nosdn.127.net/56eb25a38d7a630e76a608a9360eec6b.jpg', name: '基础百搭,儿童套头针织毛衣1-9岁', tag: '儿童服饰' },]}}
}
</script><style lang="less" scoped>
.table-case {width: 1000px;margin: 50px auto;img {width: 100px;height: 100px;object-fit: contain;vertical-align: middle;}
}</style>

main.js

import Vue from 'vue'
import App from './App.vue'Vue.config.productionTip = false// 封装全局指令 focus
Vue.directive('focus', {// 指令所在的dom元素,被插入到页面中时触发inserted(el) {el.focus()}
})new Vue({render: h => h(App),
}).$mount('#app')

四、路由入门

1.单页应用程序: SPA - Single Page Application


2.路由的介绍


3.VueRouter 的 介绍

4.VueRouter 的 使用 (5 + 2)

安装 vue-router:在项目目录下运行以下命令安装 vue-router

npm install vue-router

或者使用 yarn

yarn add vue-router

main.js

import Vue from 'vue'
import App from './App.vue'// 路由的使用步骤 5 + 2
// 5个基础步骤
// 1. 下载 v3.6.5
// 2. 引入
// 3. 安装注册 Vue.use(Vue插件)
// 4. 创建路由对象
// 5. 注入到new Vue中,建立关联// 2个核心步骤
// 1. 建组件(views目录),配规则
// 2. 准备导航链接,配置路由出口(匹配的组件展示的位置) 
import Find from './views/Find'
import My from './views/My'
import Friend from './views/Friend'
import VueRouter from 'vue-router'
Vue.use(VueRouter) // VueRouter插件初始化const router = new VueRouter({// routes 路由规则们// route  一条路由规则 { path: 路径, component: 组件 }routes: [{ path: '/find', component: Find },{ path: '/my', component: My },{ path: '/friend', component: Friend },]
})Vue.config.productionTip = falsenew Vue({render: h => h(App),router
}).$mount('#app')

App.vue

<template><div><div class="footer_wrap"><a href="#/find">发现音乐</a><a href="#/my">我的音乐</a><a href="#/friend">朋友</a></div><div class="top"><!-- 路由出口 → 匹配的组件所展示的位置 --><router-view></router-view></div></div>
</template><script>
export default {};
</script><style>
body {margin: 0;padding: 0;
}.footer_wrap {position: relative;left: 0;top: 0;display: flex;width: 100%;text-align: center;background-color: #333;color: #ccc;
}.footer_wrap a {flex: 1;text-decoration: none;padding: 20px 0;line-height: 20px;background-color: #333;color: #ccc;border: 1px solid black;
}.footer_wrap a:hover {background-color: #555;
}
</style>

Find.vue

<template><div><p>发现音乐</p><p>发现音乐</p><p>发现音乐</p><p>发现音乐</p></div>
</template><script>
export default {name: 'FindMusic'
}
</script><style></style>

Friend.vue

<template><div><p>我的朋友</p><p>我的朋友</p><p>我的朋友</p><p>我的朋友</p></div>
</template><script>
export default {name: 'MyFriend'
}
</script><style></style>

My.vue

<template><div><p>我的音乐</p><p>我的音乐</p><p>我的音乐</p><p>我的音乐</p></div>
</template><script>
export default {name: 'MyMusic'
}
</script><style></style>

5.组件存放目录问题


组件存放目录问题 (组件分类)


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

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

相关文章

本地大模型编程实战(32)用websocket显示大模型的流式输出

在与 LLM(大语言模型) 对话时&#xff0c;如果每次都等 LLM 处理完毕再返回给客户端&#xff0c;会显得比较卡顿&#xff0c;不友好。如何能够像主流的AI平台那样&#xff1a;可以一点一点吐出字符呢&#xff1f; 本文将模仿后端流式输出文字&#xff0c;前端一块一块的显示文字…

人工智能-深度学习之卷积神经网络

深度学习 mlp弊端卷积神经网络图像卷积运算卷积神经网络的核心池化层实现维度缩减卷积神经网络卷积神经网络两大特点卷积运算导致的两个问题&#xff1a;图像填充&#xff08;padding&#xff09;结构组合问题经典CNN模型LeNet-5模型AlexNet模型VGG-16模型 经典的CNN模型用于新…

蓝桥杯电子赛_继电器和蜂鸣器

目录 一 前言 二 继电器和蜂鸣器实物 三 分析部分 &#xff08;1&#xff09;bsp_init.c &#xff08;2&#xff09;蜂鸣器和继电器原理图 &#xff08;3&#xff09;ULN2003 &#xff08;4&#xff09;他们俩所连接的锁存器 四 代码 在这里要特别说一点&#xff01;&…

仿腾讯会议——主界面设计创建房间加入房间客户端实现

1、实现腾讯会议主界面 2、添加Qt类WeChatDialog 3、定义创建会议和加入会议的函数 4、实现显示名字、头像的函数 调用函数 5、在中间者类中绑定函数 6、实现创建房间的槽函数 7、实现加入房间的槽函数 8、设置界面标题 9、服务器定义创建和进入房间函数 10、服务器实现创建房间…

网络编程初识

注&#xff1a;此博文为本人学习过程中的笔记 1.socket api 这是操作系统提供的一组api&#xff0c;由传输层向应用层提供。 2.传输层的两个核心协议 传输层的两个核心协议分别是TCP协议和UDP协议&#xff0c;它们的差别非常大&#xff0c;编写代码的风格也不同&#xff0c…

【质量管理】现代TRIZ问题识别中的功能分析——功能模型

功能模型的定义 功能模型是对工程系统进行功能分析的一个阶段&#xff0c;目的是建立工程系统的功能模型。功能模型描述了工程系统和超系统组件的功能&#xff0c;包括有用功能、性能水平和成本等。 在文章【质量管理】现代TRIZ中问题识别中的功能分析——相互接触分析-CSDN博客…

广告事件聚合系统设计

需求背景 广告事件需要进行统计&#xff0c;计费&#xff0c;分析等。所以我们需要由数据接入&#xff0c;数据处理&#xff0c;数据存储&#xff0c;数据查询等多个服务模块去支持我们的广告系统 规模上 10000 0000个点击&#xff08;10000 00000 / 100k 1wQPS&#xff09; …

C语言中,sizeof关键字(详细介绍)

目录 ‌1. 基本用法‌(1) ‌基本数据类型‌(2) ‌变量‌(3) ‌数组‌(4) ‌指针‌ ‌2. 特殊用法‌(1) ‌结构体与内存对齐‌(2) ‌动态内存分配‌(3) ‌表达式‌ ‌3. 注意事项‌‌1&#xff09;sizeof 与 strlen 的区别‌&#xff1a;‌2&#xff09;变长数组&#xff08;VLA…

ADK 第三篇 Agents (LlmAgent)

Agents 在智能体开发套件&#xff08;ADK&#xff09;中&#xff0c;智能体&#xff08;Agent&#xff09;是一个独立的执行单元&#xff0c;旨在自主行动以实现特定目标。智能体能够执行任务、与用户交互、使用外部工具&#xff0c;并与其他智能体协同工作。 在ADK中&#x…

【深度学习】典型的 CNN 网络

目录 一、LeNet-5 &#xff08;1&#xff09;LeNet-5 网络概览 &#xff08;2&#xff09;网络结构详解 &#xff08;3&#xff09;关键组件与数学原理 3.1 局部感受野与卷积运算 3.2 权重共享 3.3 子采样&#xff08;Pooling&#xff09; 3.4 激活函数 &#xff08;4…

4.8/Q1,中山大学用NHANES:膳食烟酸摄入量与非酒精性脂肪肝之间的关联

文章题目&#xff1a;Association between Dietary Niacin Intake and Nonalcoholic Fatty Liver Disease: NHANES 2003-2018 DOI&#xff1a;10.3390/nu15194128 中文标题&#xff1a;膳食烟酸摄入量与非酒精性脂肪肝之间的关联&#xff1a;NHANES 2003-2018 发表杂志&#xf…

高效管理远程服务器Termius for Mac 保姆级教程

以下是 Termius for Mac 保姆级教程&#xff0c;涵盖安装配置、核心功能、实战案例及常见问题解决方案&#xff0c;助你高效管理远程服务器&#xff08;如Vultr、AWS等&#xff09;。 一、Termius 基础介绍 1. Termius 是什么&#xff1f; 跨平台SSH客户端&#xff1a;支持Ma…

理解数学概念——支集(支持)(support)

1. 支集(support)的定义 在数学中&#xff0c;一个实函数 f 的支集(support)是函数的不被映射到 0 的元素域(即定义域)的子集。若 f 的(定义)域(domain)是一个拓扑空间(即符合拓扑的集合)&#xff0c;则 f 的支集则定义为包含( f 的元素域中)不被映射到0的所有点之最小闭集…

Vue 3 Element Plus 浏览器使用例子

Element Plus 是一个基于 Vue 3 的流行开源 UI 库&#xff0c;提供了一系列的组件&#xff0c;帮助开发者快速构建现代化的用户界面。它的设计简洁、现代&#xff0c;包含了许多可定制的组件&#xff0c;如按钮、表格、表单、对话框等&#xff0c;适合用于开发各种 Web 应用。 …

SSR vs SSG:前端渲染模式终极对决(附 Next.js/Nuxt.js 实战案例)

一、引言&#xff1a;前端渲染模式的进化之路 随着互联网的发展&#xff0c;用户对于网页的加载速度和交互体验要求越来越高。前端渲染技术作为影响网页性能的关键因素&#xff0c;也在不断地发展和演进。从最初的客户端渲染&#xff08;CSR&#xff09;&#xff0c;到后来的服…

算法笔记.分解质因数

代码实现&#xff1a; #include<iostream> using namespace std; void breakdown(int x) {int t x;for(int i 2;i < x/i;i){if(t%i 0){int counts 0;while(t % i 0){t/i;counts;}cout << i <<" "<< counts<<endl;}}if(t >…

CUDA Error: the provided PTX was compiled with an unsupported toolchain

CUDA程序编译时生成的PTX代码与系统上的CUDA驱动版本不兼容 CUDA 编译器版本&#xff1a; CUDA 12.6 (nvcc 编译器版本) CUDA 驱动版本&#xff1a; CUDA 12.3 (nvidia-smi 驱动版本) 解决方法&#xff1a; 驱动版本下载参考&#xff1a;Your connected workspace for wiki…

计算机组成原理实验(7) 堆指令部件模块实验

实验七 堆指令部件模块实验 一、实验目的 1、掌握指令部件的组成方式。 2、熟悉指令寄存器的打入操作&#xff0c;PC计数器的设置和加1操作&#xff0c;理解跳转指令的实现过程。 二、实验要求 按照实验步骤完成实验项目&#xff0c;掌握数据打入指令寄存器IR1、PC计数器的…

2022 年 6 月大学英语四级考试真题(第 2 套)——阅读版——仔细阅读题

&#x1f3e0;个人主页&#xff1a;fo安方的博客✨ &#x1f482;个人简历&#xff1a;大家好&#xff0c;我是fo安方&#xff0c;目前中南大学MBA在读&#xff0c;也考取过HCIE Cloud Computing、CCIE Security、PMP、CISP、RHCE、CCNP RS、PEST 3等证书。&#x1f433; &…

磁盘文件系统

磁盘文件系统 一、磁盘结构1.1 认识一下基础的硬件设备以及真实的机房环境1.2 磁盘物理结构与存储结构1、磁盘物理结构2、磁盘的存储结构3、CHS地址定位4、磁盘的逻辑结构&#xff08;LBA&#xff09;5 磁盘真实过程5 CHS && LBA地址 二、理解分区、格式化1 引⼊"…