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

【Vue】Vue2中的Vuex

目录

  • Vuex
    • 介绍
    • Vuex 中的核心概念
  • 在vue2中使用Vuex
    • 安装 Vuex
    • 创建一个 Vuex Store
    • 在 Vue 实例中使用 Vuex
    • 编写 Vuex 的 state、mutations 和 actions
    • 在组件中使用 Vuex
  • Vuex的核心
    • State
      • 组件中获取 Vuex 的状态
      • mapState 辅助函数
      • 对象展开运算符
    • Getter
      • 基本使用
        • 示例
      • 通过属性访问
      • 通过方法访问
      • mapGetters 辅助函数
    • Mutation
      • 定义mutation
        • mutations 中回调函数参数:
      • commit 提交 mutation
      • Mutation 必须是同步函数
      • mapMutations 辅助函数
    • Actions
      • Action 函数
      • dispatch 触发 Action
      • action 内部执行异步操作
        • 购物车示例,涉及到调用异步 API 和分发多重 mutation
      • mapActions 辅助函数
      • 组合 Action
  • Modules
    • 基本使用
      • 示例:
    • 命名空间
      • 示例

Vuex

介绍

  • Vuex 是一个用于 Vue.js 应用程序的状态管理模式。
  • 它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态的一致性。
  • Vuex 还集成了Vue的官方浏览器插件 vue-devtools,提供了一些强大的调试工具。
  • Vue 2 匹配的 Vuex 3 的文档:文档链接
    在这里插入图片描述

Vuex 中的核心概念

  1. State(状态):用于存储应用程序的状态,可以通过 this.$store.state 访问。

  2. Getters(计算属性):类似于 Vue 组件中的计算属性,可以派生出一些状态,可以通过 this.$store.getters 访问。

  3. Mutations(突变):用于修改状态,只能进行同步操作,可以通过 this.$store.commit 触发。

  4. Actions(异步操作):用于处理异步操作,可以通过 this.$store.dispatch 触发,并且可以调用多个突变。

  5. Modules(模块化):可以将 store 分割成多个模块,每个模块拥有自己的 state、getters、mutations和actions。

使用 Vuex 可以帮助我们更好地组织和管理 Vue 应用的状态,并且方便状态的复用和共享。

在vue2中使用Vuex

安装 Vuex

可以使用 npm 或者 yarn 进行安装。

npm install vuex
//或者
npm install vuex@3.0.0 --save
//或者
yarn add vuex

创建一个 Vuex Store

在src/store目录下创建一个名为 index.js 的文件,并在其中导入 Vue 和 Vuex,并创建一个新的 Vuex.Store 实例。

import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state: {count: 1},mutations: {increment(state, value) {state.count += value}}
})
export default store;

在 Vue 实例中使用 Vuex

在 main.js 文件中导入刚才创建的 index.js 文件,并在 Vue 实例的配置对象中引入 store

import Vue from 'vue'
import App from './App.vue'
import store from './store'new Vue({store,render: h => h(App),
}).$mount('#app')

编写 Vuex 的 state、mutations 和 actions

对于需要进行状态管理的数据,可以在 store.js 文件中定义 state,并在 mutations 中编写修改 state 的方法,在 actions 中编写处理业务逻辑的方法。

export default new Vuex.Store({state: {count: 0,},mutations: {increment(state) {state.count++},},actions: {incrementAsync({ commit }) {setTimeout(() => {commit('increment')}, 1000)},},})

在组件中使用 Vuex

在需要使用 Vuex 中的状态或触发 Vuex 中 mutations/actions 的组件中,可以通过 this.$store.state 来获取 state,通过 this.$store.commit 来触发 mutations,通过 this.$store.dispatch 来触发 actions。

 <template><div><p>Count: {{ count }}</p><button @click="increment">Increment</button></div></template><script>export default {computed: {count() {return this.$store.state.count},},methods: {increment() {this.$store.commit('increment')},},}</script>

通过上述步骤,就可以在 Vue 2 中使用 Vuex 进行状态管理了。可以在组件中方便地共享和修改状态,并且处理异步操作。

Vuex的核心

State

组件中获取 Vuex 的状态

  • 在计算属性中返回某个状态:

    // 创建一个 Counter 组件
    const Counter = {template: `<div>{{ count }}</div>`,computed: {count () {return store.state.count}}
    }
    
  • 在每个需要使用 state 的组件中需要频繁地导入

  • 在根实例中注册 store 选项,该 store 实例会注入到根组件下的所有子组件中

    const app = new Vue({el: '#app',store, // 把 store 对象提供给 “store” 选项,这可以把 store 的实例注入所有的子组件components: { Counter },template: `<div class="app"><counter></counter></div>`
    })
    
  • 子组件能通过 this.$store 访问:

    const Counter = {template: `<div>{{ count }}</div>`,computed: {count () {return this.$store.state.count}}
    }
    

mapState 辅助函数

  • 用于组件需要获取多个状态的时候

    <template><div class="hello"><div><h3>组件中使用 store</h3>当前count:{{ $store.state.count }}</div><div><h3>组件中使用 mapState</h3><div>当前count:{{ count }}</div><div>当前countAlias:{{ countAlias }}</div><div>当前countPlusLocalState:{{ countPlusLocalState }}</div></div><div><button v-on:click="clickCount(0)">减1</button><button v-on:click="clickCount(1)">加1</button></div></div>
    </template><script>
    import { mapState } from "vuex";export default {name: "CountView",methods: {clickCount(val) {this.$store.commit("increment", val === 0 ? -1 : 1);},},data: () => ({localCount: 3,}),computed: {...mapState({// 箭头函数可使代码更简练count: (state) => state.count,// 传字符串参数 'count' 等同于 `state => state.count`countAlias: "count",// 使用常规函数,count + data中的localCountcountPlusLocalState(state) {return state.count + this.localCount;},}),},
    };
    </script>
    
  • 也可以给 mapState 传一个字符串数组:

    computed: mapState([// 映射 this.count 为 store.state.count'count'
    ])
    

对象展开运算符

```js
computed: {localComputed () { /* ... */ },// 使用对象展开运算符将此对象混入到外部对象中...mapState({// ...})
}
```

Getter

基本使用

  • 就像计算属性一样,getter 的返回值会根据它的依赖被缓存起来,且只有当它的依赖值发生了改变才会被重新计算。
示例
  • Getter 接受 2 个参数, state 作为其第一个参数,getter 作为第二个参数

    const store = new Vuex.Store({state: {todos: [{ id: 1, text: '...', done: true },{ id: 2, text: '...', done: false }]},getters: {doneTodos: (state, getters) => {return state.todos.filter(todo => todo.done)}}
    })
    

通过属性访问

  • Getter 会暴露为 store.getters 对象,可以以属性的形式访问这些值:

    store.getters.doneTodos // -> [{ id: 1, text: '...', done: true }]
    

通过方法访问

  • 也可以通过让 getter 返回一个函数,来实现给 getter 传参

    getters: {// ...getTodoById: (state) => (id) => {return state.todos.find(todo => todo.id === id)}
    }
    
  • 使用

    store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
    

mapGetters 辅助函数

  • mapGetters 辅助函数仅仅是将 store 中的 getter 映射到局部计算属性:

    import { mapGetters } from 'vuex'export default {// ...computed: {// 使用对象展开运算符将 getter 混入 computed 对象中...mapGetters(['doneTodosCount','anotherGetter',// ...])}
    }
    
  • 如果你想将一个 getter 属性另取一个名字,使用对象形式:

    ...mapGetters({// 把 `this.doneCount` 映射为 `this.$store.getters.doneTodosCount`doneCount: 'doneTodosCount'
    })
    

Mutation

定义mutation

更改状态的唯一方法是提交 mutation

mutations 中回调函数参数:
  • state 为第一个参数,
  • payload(载荷)为第二个参数(可以为基本数据类型,也可以为对象)
const store = new Vuex.Store({state: {count: 1},mutations: {increment(state, payload) {state.count += payload}}
})

commit 提交 mutation

调用 store.commit 方法:

store.commit('increment', 2)

Mutation 必须是同步函数

一条重要的原则就是要记住 mutation 必须是同步函数

mutations: {someMutation (state) {api.callAsyncMethod(() => {state.count++})}
}
  • 原因是当 mutation 触发的时候,回调函数还没有被调用,devtools 不知道什么时候回调函数实际上被调用,这样状态的变化就变得不可追踪
  • 解决方法:使用 Actions

mapMutations 辅助函数

使用 mapMutations 辅助函数将组件中的 methods 映射为 store.commit 调用:(需要先在根节点注入 store):

import { mapMutations } from 'vuex'export default {// ...methods: {...mapMutations(['increment', // 将 `this.increment()` 映射为 `this.$store.commit('increment')`// `mapMutations` 也支持载荷:'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.commit('incrementBy', amount)`]),...mapMutations({add: 'increment' // 将 `this.add()` 映射为 `this.$store.commit('increment')`})}
}

Actions

Action 类似于 mutation,不同在于:

  1. Action 提交的是 mutation,而不是直接变更状态。
  2. Action 可以包含任意异步操作。

Action 函数

Action 函数参数

  • context 对象(与 store 实例具有相同方法和属性,因此你可以调用 context.commit 提交一个 mutation)
  • payload 载荷(可以基本数据,也可以对象)

定义

const store = new Vuex.Store({state: {count: 0},mutations: {increment(state, payload) {state.count += payload;}},actions: {increment(context, payload) {context.commit('increment', payload)}}
})export default store;

dispatch 触发 Action

Action 通过 store.dispatch 方法触发:

store.dispatch('increment', 3)

action 内部执行异步操作

actions: {incrementAsync ({ commit }) {setTimeout(() => {commit('increment')}, 1000)}
}
购物车示例,涉及到调用异步 API 和分发多重 mutation
actions: {checkout ({ commit, state }, products) {// 把当前购物车的物品备份起来const savedCartItems = [...state.cart.added]// 发出结账请求,然后乐观地清空购物车commit(types.CHECKOUT_REQUEST)// 购物 API 接受一个成功回调和一个失败回调shop.buyProducts(products,// 成功操作() => commit(types.CHECKOUT_SUCCESS),// 失败操作() => commit(types.CHECKOUT_FAILURE, savedCartItems))}
}

mapActions 辅助函数

使用 mapActions 辅助函数将组件的 methods 映射为 store.dispatch 调用(需要先在根节点注入 store):

import { mapActions } from 'vuex'export default {// ...methods: {...mapActions(['increment', // 将 `this.increment()` 映射为 `this.$store.dispatch('increment')`// `mapActions` 也支持载荷:'incrementBy' // 将 `this.incrementBy(amount)` 映射为 `this.$store.dispatch('incrementBy', amount)`]),...mapActions({add: 'increment' // 将 `this.add()` 映射为 `this.$store.dispatch('increment')`})}
}

组合 Action

Action 通常是异步的,那么如何知道 action 什么时候结束呢?更重要的是,我们如何才能组合多个 action,以处理更加复杂的异步流程?
首先,你需要明白 store.dispatch 可以处理被触发的 action 的处理函数返回的 Promise,并且 store.dispatch 仍旧返回 Promise:

actions: {actionA ({ commit }) {return new Promise((resolve, reject) => {setTimeout(() => {commit('someMutation')resolve()}, 1000)})}
}

现在这么写

store.dispatch('actionA').then(() => {// ...
})

在另外一个 action 中也可以:

actions: {// ...actionB ({ dispatch, commit }) {return dispatch('actionA').then(() => {commit('someOtherMutation')})}
}

最后,如果我们利用 async / await (opens new window),我们可以如下组合 action:

// 假设 getData() 和 getOtherData() 返回的是 Promise
actions: {async actionA ({ commit }) {commit('gotData', await getData())},async actionB ({ dispatch, commit }) {await dispatch('actionA') // 等待 actionA 完成commit('gotOtherData', await getOtherData())}
}

Modules

基本使用

  • Vuex 允许我们将 store 分割成模块(module)
  • 每个模块拥有自己的 state、mutation、action、getter

示例:

store/modules/moduleA.js

const moduleA = {state: {countA: 1},getters: {},mutations: {},actions: {}
}export default moduleA;

store/modules/moduleB.js

const moduleB = {state: {countB: 2},getters: {sumWithRootCount(state, getters, rootState) {// 这里的 state 和 getters 对象是模块的局部状态,rootState 为根节点状态console.log('B-state', state)console.log('B-getters', getters)console.log('B-rootState', rootState)return state.countB + rootState.count}},mutations: {increment(state, payload) {// 这里的 `state` 对象是模块的局部状态state.countB += payload;}},actions: {incrementIfOddOnRootSum({ state, commit, rootState }, payload) {console.log(payload)// 这里的 `state` 对象是模块的局部状态,rootState 为根节点状态console.log(state)commit('increment', rootState.count + payload)}}
}export default moduleB;

src/store/index.js

import Vue from 'vue'
import Vuex from 'vuex'
import moduleA from './modules/moduleA'
import moduleB from './modules/moduleB'Vue.use(Vuex)const store = new Vuex.Store({state: {count: 5},modules: {moduleA: moduleA,moduleB: moduleB,}
})export default store;

组件中使用

<template><div class="hello"><div><h3>组件中使用 store</h3><div>moduleA中的countA {{ countA }}</div><div>moduleB中的countB {{ countB }}</div></div><div><button v-on:click="clickCommit(1)">commit 加1</button><button v-on:click="clickDispatch(1)">dispatch 加1</button></div></div>
</template><script>export default {name: "CountView",methods: {clickCommit(val) {this.$store.commit("increment", val);},clickDispatch(val) {this.$store.dispatch("incrementIfOddOnRootSum", val);},},computed: {countA() {// moduleA 中的 countAreturn this.$store.state.moduleA.countA;},countB() {// moduleB 中的 countBreturn this.$store.state.moduleB.countB;},},
};
</script>

命名空间

  • 默认情况下,模块内部的 action、mutation 和 getter 是注册在全局命名空间的——这样使得多个模块能够对同一 mutation 或 action 作出响应
  • 可以通过添加 namespaced: true 的方式使其成为带命名空间的模块。
  • 当模块被注册后,它的所有 getter、action 及 mutation 都会自动根据模块注册的路径调整命名。

示例

store/modules/moduleA.js

const moduleA = {namespaced: true, // 设为命名空间state: {countA: 1},getters: {},mutations: {},actions: {}
}export default moduleA;

store/modules/moduleB.js

const moduleB = {namespaced: true, // 设为命名空间state: {countB: 2},getters: {sumWithRootCount(state, getters, rootState) {// 这里的 state 和 getters 对象是模块的局部状态,rootState 为根节点状态console.log('B-state', state)console.log('B-getters', getters)console.log('B-rootState', rootState)return state.countB + rootState.count}},mutations: {increment(state, payload) {// 这里的 `state` 对象是模块的局部状态state.countB += payload;}},actions: {incrementIfOddOnRootSum({ state, commit, rootState }, payload) {console.log(payload)// 这里的 `state` 对象是模块的局部状态,rootState 为根节点状态console.log(state)commit('increment', rootState.count + payload)}}
}export default moduleB;

src/store/index.js

import Vue from 'vue'
import Vuex from 'vuex'
import moduleA from './modules/moduleA'
import moduleB from './modules/moduleB'Vue.use(Vuex)const store = new Vuex.Store({state: {count: 5},modules: {moduleA: moduleA,moduleB: moduleB,}
})export default store;

组件中使用

<template><div class="hello"><div><h3>组件中使用 store</h3><div>moduleA中的countA {{ countA }}</div><div>moduleB中的countB {{ countB }}</div></div><div><button v-on:click="increment(1)">commit 加1</button><button v-on:click="incrementIfOddOnRootSum(1)">dispatch 加1</button></div></div>
</template><script>
import { mapActions, mapMutations, mapState } from "vuex";export default {name: "CountView",methods: {// 将模块的空间名称字符串作为第一个参数传递给 mapMutations...mapMutations("moduleB", ["increment"]),// 将模块的空间名称字符串作为第一个参数传递给 mapActions...mapActions("moduleB", ["incrementIfOddOnRootSum"]),},computed: {// 将模块的空间名称字符串作为第一个参数传递给 mapState...mapState("moduleA", {countA: (state) => state.countA,}),...mapState("moduleB", {countB: (state) => state.countB,}),},
};
</script>

相关文章:

【Vue】Vue2中的Vuex

目录 Vuex介绍Vuex 中的核心概念 在vue2中使用Vuex安装 Vuex创建一个 Vuex Store在 Vue 实例中使用 Vuex编写 Vuex 的 state、mutations 和 actions在组件中使用 Vuex Vuex的核心State组件中获取 Vuex 的状态mapState 辅助函数对象展开运算符 Getter基本使用示例 通过属性访问通…...

前端生成二维码

直接img标签显示 npm i use_qrcode npm包地址 <img :src"qrcode" alt"QR Code" /> const txt: any ref(https://baidu.com) const qrcode useQRCode(txt) const qrcodeLogo useQRCode(txt, { logoSrc: https://www.antdv.com/assets/logo.1ef800…...

wordpress woocommer 添加代码实现,点击按钮,将产品添加到购物车并且跳转到结账页面

wordpress woocommer 添加代码实现&#xff0c;点击按钮&#xff0c;将产品添加到购物车并且跳转到结账页面 案列代码1&#xff0c;解决的是普通产品的 //短代码生成按钮&#xff0c;传入短代码&#xff0c;点击直接到达结账页面 function add_product_to_cart_button($atts)…...

Scala学习笔记6: 类

目录 第六章 类1- 简单类和无参方法2- 带有getter和setter的属性3- 只带getter的属性4- 对象私有化5- 辅助构造器6- 主构造器7- 嵌套类end 第六章 类 在Scala中, 类用于创建对象的蓝图; 类可以包含方法、值、变量、类型、对象和特质等成员; 类名应该以大写字母开头, 可以包含…...

JS数组根据对象的某一个字段排序

const person [{ name: aa, age: 9 },{ name: bb, age: 17 },{ name: cc, age: 6 },{ name: dd, age: 18 }];// 升序const arr1 person.sort((a, b) > {return a.age - b.age;b})console.log(arr1)// 降序const arr2 person.sort((a, b) > {return b.age - a.age;})co…...

JavaScript操作

做UI自动化的时候&#xff0c;有些操作无法直接通过selenium自带方法操 作成功&#xff0c;那么就需要借助前端js操作实现。 比如浏览器的滚动条这种不是html页面的内容&#xff0c;无法直接通过selenium 控制到。需要借助JavaScript控制。比如有些点击操作无法通过普通点击鼠…...

雪花算法 代码

/*** author lwh* date 2023/9/5* description 批量插入&#xff0c;手动设置**/ public class IdWorker {//因为二进制里第一个 bit 为如果是 1&#xff0c;那么都是负数&#xff0c;但是我们生成的 id 都是正数&#xff0c;所以第一个 bit 统一都是 0。//机器ID 2进制5位 3…...

我把PostgreSQL最核心的插件撸干净了!!!

作者&#xff1a;IT邦德 中国DBA联盟(ACDU)成员&#xff0c;10余年DBA工作经验&#xff0c; Oracle、PostgreSQL ACE CSDN博客专家及B站知名UP主&#xff0c;全网粉丝10万 擅长主流Oracle、MySQL、PG、高斯及Greenplum备份恢复&#xff0c; 安装迁移&#xff0c;性能优化、故障…...

Transformer详解(1)-结构解读

Transormer块主要由四个部分组成&#xff0c;注意力层、位置感知前馈神经网络、残差连接和层归一化。 1、注意力层(Multi-Head Attention) 使用多头注意力机制整合上下文语义&#xff0c;它使得序列中任意两个单词之间的依赖关系可以直接被建模而不基于传统的循环结构&#…...

使用Flask Swagger自动生成API文档

文章目录 安装Flask Swagger使用Flask Swagger生成API文档总结1. 自动化文档生成2. 交互式文档展示3. 规范化API设计4. 提升协作效率5. 支持多种格式 Flask Swagger是一种用于管理Flask API文档的工具。它基于OpenAPI规范&#xff0c;可以自动生成API的交互式文档。使用Flask S…...

操作系统408考研-经典例题

什么是操作系统?答:操作系统,是计算机系统中最基本、最重要的系统软件,是其它软件 的***支撑***。控制和管理计算机系统的硬件和软件资源,合理的组织计算机工 作流程,并为用户使用计算机提供公共和基本的服务 2.多道程序 (multiprogrammming) 和多重处理 (multiprocessi…...

工程项目管理系统源码与Spring Cloud:实现高效系统管理与二次开发

随着企业规模的不断扩大和业务的快速发展&#xff0c;传统的工程项目管理方式已经无法满足现代企业的需求。为了提高工程管理效率、减轻劳动强度、提高信息处理速度和准确性&#xff0c;企业需要借助先进的数字化技术进行转型。本文将介绍一款采用Spring CloudSpring BootMybat…...

react中hook 函数的使用

以 use 开头的函数被称为 Hook。useState 是 React 提供的一个内置 Hook。你可以在 React API 参考 中找到其他内置的 Hook。你也可以通过组合现有的 Hook 来编写属于你自己的 Hook。 Hook 比普通函数更为严格。你只能在你的组件&#xff08;或其他 Hook&#xff09;的 顶层 调…...

探索k8s集群中kubectl的陈述式资源管理

一、k8s集群资源管理方式分类 1.1陈述式资源管理方式&#xff1a;增删查比较方便&#xff0c;但是改非常不方便 使用一条kubectl命令和参数选项来实现资源对象管理操作 即通过命令的方式来实 1.2声明式资源管理方式&#xff1a;yaml文件管理 使用yaml配置文件或者json配置文…...

webgl入门-绘制三角形

绘制三角形 前言 三角形是一个最简单、最稳定的面&#xff0c;webgl 中的三维模型都是由三角面组成的。咱们这一篇就说一下三角形的绘制方法。 课堂目标 理解多点绘图原理。可以绘制三角形&#xff0c;并将其组合成多边形。 知识点 缓冲区对象点、线、面图形 第一章 web…...

深入分析 Android Activity (三)

深入分析 Android Activity (三) 1. Activity 的配置变化处理 当设备配置&#xff08;如屏幕方向、语言、屏幕大小等&#xff09;发生变化时&#xff0c;默认情况下&#xff0c;Android 会销毁并重新创建当前的 Activity。这种行为确保了新配置能够正确应用&#xff0c;但在某…...

电影《朝云暮雨》观后感

上周看了电影《朝云暮雨》&#xff0c;看完之后&#xff0c;感觉自己整个人都不太好了&#xff0c;也不是说电影太差&#xff0c;只是觉得电影没有传达正能量&#xff0c;让人很不舒服。 &#xff08;1&#xff09;演技在线 对于著名的演员“范伟”&#xff0c;或者说&#x…...

Isaac Sim仿真平台学习(1)认识Isaac Sim

0.前言 上一个教程中我们下载好了Isaac Sim&#xff0c;这一章我们将来简单了解一下Isaac Sim平台。 isaac Sim仿真平台安装-CSDN博客 1.Isaac Sim是啥&#xff1f; What Is Isaac Sim? — Omniverse IsaacSim latest documentation Isaac Sim是NVDIA Omniverse平台的机器…...

C++:vector基础讲解

hello&#xff0c;各位小伙伴&#xff0c;本篇文章跟大家一起学习《C&#xff1a;vector基础讲解》&#xff0c;感谢大家对我上一篇的支持&#xff0c;如有什么问题&#xff0c;还请多多指教 &#xff01; 如果本篇文章对你有帮助&#xff0c;还请各位点点赞&#xff01;&#…...

Grafana 路径遍历所有路径 CVE-2021-43798漏洞预警

简介​ ​Grafana是一个跨平台、开源的数据可视化网络应用程序平台。用户配置连接的数据源之后&#xff0c;Grafana可以在网络浏览器里显示数据图表和警告。 漏洞危害等级 高危 CVE 编号​ CVE-2021-43798 FOFA查询 ​app"Grafana" ​zoomeyes查询 ​app:"gr…...

解锁数据库简洁之道:FastAPI与SQLModel实战指南

在构建现代Web应用程序时&#xff0c;与数据库的交互无疑是核心环节。虽然传统的数据库操作方式&#xff08;如直接编写SQL语句与psycopg2交互&#xff09;赋予了我们精细的控制权&#xff0c;但在面对日益复杂的业务逻辑和快速迭代的需求时&#xff0c;这种方式的开发效率和可…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序

一、开发准备 ​​环境搭建​​&#xff1a; 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 ​​项目创建​​&#xff1a; File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...

ffmpeg(四):滤镜命令

FFmpeg 的滤镜命令是用于音视频处理中的强大工具&#xff0c;可以完成剪裁、缩放、加水印、调色、合成、旋转、模糊、叠加字幕等复杂的操作。其核心语法格式一般如下&#xff1a; ffmpeg -i input.mp4 -vf "滤镜参数" output.mp4或者带音频滤镜&#xff1a; ffmpeg…...

如何将联系人从 iPhone 转移到 Android

从 iPhone 换到 Android 手机时&#xff0c;你可能需要保留重要的数据&#xff0c;例如通讯录。好在&#xff0c;将通讯录从 iPhone 转移到 Android 手机非常简单&#xff0c;你可以从本文中学习 6 种可靠的方法&#xff0c;确保随时保持连接&#xff0c;不错过任何信息。 第 1…...

Nginx server_name 配置说明

Nginx 是一个高性能的反向代理和负载均衡服务器&#xff0c;其核心配置之一是 server 块中的 server_name 指令。server_name 决定了 Nginx 如何根据客户端请求的 Host 头匹配对应的虚拟主机&#xff08;Virtual Host&#xff09;。 1. 简介 Nginx 使用 server_name 指令来确定…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

C# SqlSugar:依赖注入与仓储模式实践

C# SqlSugar&#xff1a;依赖注入与仓储模式实践 在 C# 的应用开发中&#xff0c;数据库操作是必不可少的环节。为了让数据访问层更加简洁、高效且易于维护&#xff0c;许多开发者会选择成熟的 ORM&#xff08;对象关系映射&#xff09;框架&#xff0c;SqlSugar 就是其中备受…...

Kafka入门-生产者

生产者 生产者发送流程&#xff1a; 延迟时间为0ms时&#xff0c;也就意味着每当有数据就会直接发送 异步发送API 异步发送和同步发送的不同在于&#xff1a;异步发送不需要等待结果&#xff0c;同步发送必须等待结果才能进行下一步发送。 普通异步发送 首先导入所需的k…...

云原生安全实战:API网关Kong的鉴权与限流详解

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、基础概念 1. API网关&#xff08;API Gateway&#xff09; API网关是微服务架构中的核心组件&#xff0c;负责统一管理所有API的流量入口。它像一座…...

SQL Server 触发器调用存储过程实现发送 HTTP 请求

文章目录 需求分析解决第 1 步:前置条件,启用 OLE 自动化方式 1:使用 SQL 实现启用 OLE 自动化方式 2:Sql Server 2005启动OLE自动化方式 3:Sql Server 2008启动OLE自动化第 2 步:创建存储过程第 3 步:创建触发器扩展 - 如何调试?第 1 步:登录 SQL Server 2008第 2 步…...