【vuex】

vuex

  • 1 理解vuex
    • 1.1 vuex是什么
    • 1.2 什么時候使用vuex
    • 1.3 vuex工作原理圖
    • 1.4 搭建vuex環境
    • 1.5 求和案例
      • 1.5.1 vue方式
      • 1.5.2 vuex方式
  • 2 vuex核心概念和API
    • 2.1 getters配置項
    • 2.2 四個map方法的使用
      • 2.2.1 mapState方法
      • 2.2.2 mapGetters方法
      • 2.2.3 mapActions方法
      • 2.2.4 mapMutations方法
      • 2.2.5 求和案例之四個map的使用
    • 2.3 多組件共享數據
    • 2.4 模塊化+命名空間

1 理解vuex

1.1 vuex是什么

  • 概念:專門在 Vue 中實現集中式狀態(數據)管理的一個 Vue 插件,對 Vue 應用中多個組件的共享狀態進行集中式的管理(讀/寫),也是一種組件間通信的方式,且適用于任意組件間通信。
    在這里插入圖片描述
    在這里插入圖片描述

1.2 什么時候使用vuex

  • 多個組件依賴于同一狀態
  • 來自不同組件的行為需要變更同一狀態

1.3 vuex工作原理圖

在這里插入圖片描述

1.4 搭建vuex環境

  • npm i vuex
vue2中,要用vuex的3版本
vue3中,要用vuex的4版本

在這里插入圖片描述

  • Vue.use(Vuex)
    在這里插入圖片描述
  • 創建store
    方法一:
    在這里插入圖片描述
    方法二(推薦):
    在這里插入圖片描述
  • vc ? store
// 引入Vue
import Vue from 'vue'
// 引入App
import App from './App.vue'
// 引入插件vue-resource
import vueResource from 'vue-resource'
// 引入store
import store from './store/index'
// 關閉Vue的生產提示
Vue.config.productionTip = false// 使用插件
Vue.use(vueResource)// 創建vm
new Vue({el:'#app',render: h => h(App),// store:store,store,// 安裝全局事件總線beforeCreate(){Vue.prototype.$bus = this}
})

在這里插入圖片描述

// 該文件用于創建Vuex中最為核心的store// 引入Vue
import Vue from 'vue'
// 引入Vuex
import Vuex from 'vuex'
// 使用vuex
Vue.use(Vuex)// 準備actions--用于響應組件中的動作
const actions = {}
// 準備mutations--用于操作數據(state)
const mutations = {}
// 準備state--用于存儲數據
const state = {}// 創建并暴露store
export default new Vuex.Store({/* actions:actions,mutations:mutations,state:state, */// 簡寫為:actions,mutations,state,
})// 暴露(導出)store
// export default store

在這里插入圖片描述

1.5 求和案例

1.5.1 vue方式

  • App.vue代碼:
<template><div><Count/></div>
</template><script>import Count from './components/Count.vue'export default {name:'App',components:{Count},}
</script>
  • Count.vue代碼:
<template><div><h1>當前求和為:{{sum}}</h1><!-- 寫法一 --><!-- <select v-model="n"><option :value="1">1</option>加上冒號就是v-bind 雙引號及其內的東西當作js表達式解析,為數字型;如不加冒號,則是字符串型<option :value="2">2</option><option :value="3">3</option></select> --><!-- 寫法二(強制轉換) --><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment">+</button><button @click="decrement">-</button><button @click="incrementOdd">當前求和為奇數再加</button><button @click="incrementWait">等一等再加</button></div>
</template><script>export default {name:'Count',data() {return {n:1, // 用戶選擇的數字sum:0 // 當前的和}},methods: {// 加increment(){this.sum += this.n},// 減decrement(){this.sum -= this.n},// 當前求和為奇數再加incrementOdd(){if(this.sum % 2) {this.sum += this.n}},// 等一等再加incrementWait(){setTimeout(() => {this.sum += this.n},500)}}}
</script><style lang="css">button {margin-left: 5px;}
</style>

1.5.2 vuex方式

  • main.js代碼:
// 引入Vue
import Vue from 'vue'
// 引入App
import App from './App.vue'
// 引入插件vue-resource
import vueResource from 'vue-resource'
// 引入store
import store from './store/index'
// 關閉Vue的生產提示
Vue.config.productionTip = false// 使用插件
Vue.use(vueResource)// 創建vm
new Vue({el:'#app',render: h => h(App),// store:store,store,// 安裝全局事件總線beforeCreate(){Vue.prototype.$bus = this}
})
  • index.js代碼:
// 該文件用于創建Vuex中最為核心的store// 引入Vue
import Vue from 'vue'
// 引入Vuex
import Vuex from 'vuex'
// 使用vuex
Vue.use(Vuex)// 準備actions--用于響應組件中的動作
const actions = {// 下列jia和jian沒存在意義 所以可注釋掉// jia:function(){ 簡寫為/* jia(context,value){ // context意思是上下文 把commit放進了context內// console.log('actions中的jia被調用了',context,value);context.commit('JIA',value)},jian(context,value){// console.log('actions中的jian被調用了',context,value);context.commit('JIAN',value)}, */jiaOdd(context,value){// console.log('actions中的jiaOdd被調用了',context,value);if(context.state.sum % 2){context.commit('JIA',value)}},jiaWait(context,value){// console.log('actions中的jiaWait被調用了',context,value);setTimeout(()=>{context.commit('JIA',value)},500)}
}
// 準備mutations--用于操作數據(state)
const mutations = {JIA(state,value){// console.log('mutations中的JIA被調用了',state,value);state.sum += value},JIAN(state,value){state.sum -= value}
}
// 準備state--用于存儲數據
const state = {sum:0 // 當前的和
}// 創建并暴露store
export default new Vuex.Store({/* actions:actions,mutations:mutations,state:state, */// 簡寫為:actions,mutations,state,
})// 暴露(導出)store
// export default store
  • Count.vue代碼:
<template><div><h1>當前求和為:{{$store.state.sum}}</h1><!-- 寫法一 --><!-- <select v-model="n"><option :value="1">1</option>加上冒號就是v-bind 雙引號及其內的東西當作js表達式解析,為數字型;如不加冒號,則是字符串型<option :value="2">2</option><option :value="3">3</option></select> --><!-- 寫法二(強制轉換) --><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment">+</button><button @click="decrement">-</button><button @click="incrementOdd">當前求和為奇數再加</button><button @click="incrementWait">等一等再加</button></div>
</template><script>export default {name:'Count',data() {return {n:1, // 用戶選擇的數字}},methods: {// 加increment(){// 如經過actions這樣寫:// this.$store.dispatch('jia',this.n) // $store是在vc身上// 如不經過actions這樣寫:this.$store.commit('JIA',this.n)},// 減decrement(){// 如經過actions這樣寫:// this.$store.dispatch('jian',this.n)// 如不經過actions這樣寫:this.$store.commit('JIAN',this.n)},// 當前求和為奇數再加incrementOdd(){if(this.$store.state.sum % 2) {this.$store.dispatch('jiaOdd',this.n)}},// 等一等再加incrementWait(){this.$store.dispatch('jiaWait',this.n)}}}
</script><style lang="css">button {margin-left: 5px;}
</style>

在這里插入圖片描述

2 vuex核心概念和API

2.1 getters配置項

  • 概念:當state中的數據需要經過加工后再使用時,可以使用getters加工。
    在這里插入圖片描述
    在這里插入圖片描述
    在這里插入圖片描述

2.2 四個map方法的使用

2.2.1 mapState方法

  • 用于幫助我們映射state中的數據為計算屬性
computed: {//借助mapState生成計算屬性:sum、school、subject(對象寫法)...mapState({sum:'sum',school:'school',subject:'subject'}),//借助mapState生成計算屬性:sum、school、subject(數組寫法)...mapState(['sum','school','subject']),
},

2.2.2 mapGetters方法

  • 用于幫助我們映射getters中的數據為計算屬性
computed: {//借助mapGetters生成計算屬性:bigSum(對象寫法)...mapGetters({bigSum:'bigSum'}),//借助mapGetters生成計算屬性:bigSum(數組寫法)...mapGetters(['bigSum'])
},

2.2.3 mapActions方法

  • 用于幫助我們生成與actions對話的方法,即:包含$store.dispatch(xxx)的函數
methods:{//靠mapActions生成:incrementOdd、incrementWait(對象形式)...mapActions({incrementOdd:'jiaOdd',incrementWait:'jiaWait'})//靠mapActions生成:incrementOdd、incrementWait(數組形式)...mapActions(['jiaOdd','jiaWait'])
}

2.2.4 mapMutations方法

  • 用于幫助我們生成與mutations對話的方法,即:包含$store.commit(xxx)的函數
methods:{//靠mapActions生成:increment、decrement(對象形式)...mapMutations({increment:'JIA',decrement:'JIAN'}),//靠mapMutations生成:JIA、JIAN(對象形式)...mapMutations(['JIA','JIAN']),
}
  • 備注:mapActions與mapMutations使用時,若需要傳遞參數需要:在模板中綁定事件時傳遞好參數,否則參數是事件對象。

2.2.5 求和案例之四個map的使用

  • Count.vue代碼:
<template><div><h1>當前求和為:{{sum}}</h1><h3>當前求和放大10倍后為:{{bigSum}}</h3><h3>我在{{school}}學習{{subject}}</h3><!-- 寫法一 --><!-- <select v-model="n"><option :value="1">1</option>加上冒號就是v-bind 雙引號及其內的東西當作js表達式解析,為數字型;如不加冒號,則是字符串型<option :value="2">2</option><option :value="3">3</option></select> --><!-- 寫法二(強制轉換) --><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><!-- <button @click="increment(n)">+</button><button @click="decrement(n)">-</button> --><button @click="JIA(n)">+</button><button @click="JIAN(n)">-</button><!-- <button @click="incrementOdd(n)">當前求和為奇數再加</button><button @click="incrementWait(n)">等一等再加</button> --><button @click="jiaOdd(n)">當前求和為奇數再加</button><button @click="jiaWait(n)">等一等再加</button></div>
</template><script>// 引入import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'export default {name:'Count',data() {return {n:1, // 用戶選擇的數字}},computed:{// 靠程序員自己親自去寫計算屬性/*  sum(){return this.$store.state.sum},school(){return this.$store.state.school},subject(){return this.$store.state.subject}, */// 借助mapState生成計算屬性,從state中讀取數據(對象寫法)// 在一個Obj1里面 ...Obj2, 表示把Obj2里面的每一項key:value展開放入Obj1中// ...mapState({sum:'sum',school:'school',subject:'subject'}),// 借助mapState生成計算屬性,從state中讀取數據(數組寫法)...mapState(['sum','school','subject']),// ****************************************************************************// 靠程序員自己親自去寫計算屬性/* bigSum(){return this.$store.getters.bigSum} */// 借助mapGetters生成計算屬性,從getters中讀取數據(對象寫法)// ...mapGetters({bigSum:'bigSum'})// 借助mapGetters生成計算屬性,從getters中讀取數據(數組寫法)...mapGetters(['bigSum'])},methods: {// 程序員親自寫方法// 加/*  increment(){// 如經過actions這樣寫:// this.$store.dispatch('jia',this.n) // $store是在vc身上// 如不經過actions這樣寫:this.$store.commit('JIA',this.n)}, */// 減/* decrement(){// 如經過actions這樣寫:// this.$store.dispatch('jian',this.n)// 如不經過actions這樣寫:this.$store.commit('JIAN',this.n)},*/// 借助mapMutations生成對應的方法,方法中會調用commit為聯系mutations(對象寫法)// ...mapMutations({increment:'JIA',decrement:'JIAN'}),// ...mapMutations({JIA:'JIA',JIAN:'JIAN'}),// 借助mapMutations生成對應的方法,方法中會調用commit為聯系mutations(數組寫法)...mapMutations(['JIA','JIAN']),// ****************************************************************************// 程序員親自寫方法// 當前求和為奇數再加/* incrementOdd(){if(this.$store.state.sum % 2) {this.$store.dispatch('jiaOdd',this.n)}},// 等一等再加incrementWait(){this.$store.dispatch('jiaWait',this.n)}, */// 借助mapActions生成對應的方法,方法中會調用dispatch為聯系actions(對象寫法)// ...mapActions({incrementOdd:'jiaOdd',incrementWait:'jiaWait'}),// ...mapActions({jiaOdd:'jiaOdd',jiaWait:'jiaWait'}),// 借助mapActions生成對應的方法,方法中會調用dispatch為聯系actions(數組寫法)...mapActions(['jiaOdd','jiaWait']),},/* mounted() {console.log('Count',this.$store);} */}
</script><style lang="css">button {margin-left: 5px;}
</style>

在這里插入圖片描述

2.3 多組件共享數據

在這里插入圖片描述

  • App.vue代碼:
<template><div><Count/><hr><Person/></div>
</template><script>import Count from './components/Count.vue'import Person from './components/Person.vue'export default {name:'App',components:{Count,Person},}
</script>
  • index.js代碼:
// 該文件用于創建Vuex中最為核心的store// 引入Vue
import Vue from 'vue'
// 引入Vuex
import Vuex from 'vuex'
// 使用vuex
Vue.use(Vuex)// 準備actions--用于響應組件中的動作
const actions = {// 下列jia和jian沒存在意義 所以可注釋掉// jia:function(){ 簡寫為/* jia(context,value){ // context意思是上下文 把commit放進了context內// console.log('actions中的jia被調用了',context,value);context.commit('JIA',value)},jian(context,value){// console.log('actions中的jian被調用了',context,value);context.commit('JIAN',value)}, */jiaOdd(context,value){// console.log('actions中的jiaOdd被調用了',context,value);if(context.state.sum % 2){context.commit('JIA',value)}},jiaWait(context,value){// console.log('actions中的jiaWait被調用了',context,value);setTimeout(()=>{context.commit('JIA',value)},500)}
}
// 準備mutations--用于操作數據(state)
const mutations = {JIA(state,value){// console.log('mutations中的JIA被調用了',state,value);state.sum += value},JIAN(state,value){// console.log('mutations中的JIAN被調用了',state,value);state.sum -= value},ADD_PERSON(state,value){// console.log('mutations中的ADD_PERSON被調用了',state,value);state.personList.unshift(value)}
}
// 準備state--用于存儲數據
const state = {sum:0, // 當前的和school:'霍格沃茲魔法學院',subject:'前端',personList:[{id:'001',name:'小王'}]
}
// 準備getters配置項--用于將state中的數據進行加工
const getters = {bigSum(state){return state.sum*10}
}// 創建并暴露store
export default new Vuex.Store({/* actions:actions,mutations:mutations,state:state, */// 簡寫為:actions,mutations,state,getters
})// 暴露(導出)store
// export default store
  • Count.vue代碼:
<template><div><h1>當前求和為:{{sum}}</h1><h3>當前求和放大10倍后為:{{bigSum}}</h3><h3>我在{{school}}學習{{subject}}</h3><h3 style="color:red">Person組件的總人數是:{{personList.length}}</h3><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment(n)">+</button><button @click="decrement(n)">-</button><button @click="incrementOdd(n)">當前求和為奇數再加</button><button @click="incrementWait(n)">等一等再加</button></div>
</template><script>// 引入import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'export default {name:'Count',data() {return {n:1, // 用戶選擇的數字}},computed:{// 借助mapState生成計算屬性,從state中讀取數據(數組寫法)...mapState(['sum','school','subject','personList']),// 借助mapGetters生成計算屬性,從getters中讀取數據(數組寫法)...mapGetters(['bigSum'])},methods: {// 借助mapMutations生成對應的方法,方法中會調用commit為聯系mutations(對象寫法)...mapMutations({increment:'JIA',decrement:'JIAN'}),// 借助mapActions生成對應的方法,方法中會調用dispatch為聯系actions(對象寫法)...mapActions({incrementOdd:'jiaOdd',incrementWait:'jiaWait'}),},/* mounted() {console.log('Count',this.$store);} */}
</script><style lang="css">button {margin-left: 5px;}
</style>
  • Person.vue代碼:
<template><div><h1>人員列表</h1><h3 style="color:red">Count組件求和為:{{sum}}</h3><input type="text" placeholder="請輸入名字" v-model="name"><button @click="add">添加</button><ul><li v-for="p in personList" :key="p.id">{{p.name}}</li></ul></div>
</template><script>import {nanoid} from 'nanoid'export default {name:'Person',data(){return {name:''}},computed: {personList() {return this.$store.state.personList},sum() {return this.$store.state.sum}},methods: {add() {const personObj = {id:nanoid(),name:this.name}// console.log(personObj);this.$store.commit('ADD_PERSON',personObj)this.name = '' // 添加完成后 輸入框為空}},}
</script>

在這里插入圖片描述

2.4 模塊化+命名空間

  • 目的:讓代碼更好維護,讓多種數據分類更加明確。
  • index.js修改為:在這里插入圖片描述
// 該文件用于創建Vuex中最為核心的store// 引入Vue
import Vue from 'vue'
// 引入Vuex
import Vuex from 'vuex'
// 使用vuex
Vue.use(Vuex)import axios from 'axios'
import {nanoid} from 'nanoid'// 求和相關的配置
const countOptions = {namespaced:true, // 開啟命名空間actions:{jiaOdd(context,value){// console.log('actions中的jiaOdd被調用了',context,value);if(context.state.sum % 2){context.commit('JIA',value)}},jiaWait(context,value){// console.log('actions中的jiaWait被調用了',context,value);setTimeout(()=>{context.commit('JIA',value)},500)}},mutations:{JIA(state,value){// console.log('mutations中的JIA被調用了',state,value);state.sum += value},JIAN(state,value){// console.log('mutations中的JIAN被調用了',state,value);state.sum -= value},},state:{sum:0, // 當前的和school:'霍格沃茲魔法學院',subject:'前端',},getters:{bigSum(state){return state.sum*10}}
}// 人員管理相關的配置
const personOptions = {namespaced:true, // 開啟命名空間actions:{addPersonWang(context,value){if(value.name.indexOf('王') === 0){ // 包含王且第一個為王(姓王)context.commit('ADD_PERSON',value)}else{alert('添加的人必須姓王')}},addPersonServer(context){axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(response => {context.commit('ADD_PERSON',{ID:nanoid(),name:response.data})},error => {alert(error.message)})}},mutations:{ADD_PERSON(state,value){// console.log('mutations中的ADD_PERSON被調用了',state,value);state.personList.unshift(value)}},state:{personList:[{id:'001',name:'小王'}]},getters:{firstPersonName(state){return state.personList[0].name}}
}// 準備actions--用于響應組件中的動作
/* const actions = {jiaOdd(context,value){// console.log('actions中的jiaOdd被調用了',context,value);if(context.state.sum % 2){context.commit('JIA',value)}},jiaWait(context,value){// console.log('actions中的jiaWait被調用了',context,value);setTimeout(()=>{context.commit('JIA',value)},500)}
} */
// 準備mutations--用于操作數據(state)
/* const mutations = {JIA(state,value){// console.log('mutations中的JIA被調用了',state,value);state.sum += value},JIAN(state,value){// console.log('mutations中的JIAN被調用了',state,value);state.sum -= value},ADD_PERSON(state,value){// console.log('mutations中的ADD_PERSON被調用了',state,value);state.personList.unshift(value)}
} */
// 準備state--用于存儲數據
/* const state = {sum:0, // 當前的和school:'霍格沃茲魔法學院',subject:'前端',personList:[{id:'001',name:'小王'}]
} */
// 準備getters配置項--用于將state中的數據進行加工
/* const getters = {bigSum(state){return state.sum*10}
} */// 創建并暴露store
export default new Vuex.Store({/* actions:actions,mutations:mutations,state:state, */// 簡寫為:/* actions,mutations,state,getters */modules:{countAbout:countOptions,personAbout:personOptions}
})// 暴露(導出)store==
// export default store
  • Count.vue改為:
    在這里插入圖片描述
<template><div><h1>當前求和為:{{sum}}</h1><h3>當前求和放大10倍后為:{{bigSum}}</h3><h3>我在{{school}}學習{{subject}}</h3><h3 style="color:red">Person組件的總人數是:{{personList.length}}</h3><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment(n)">+</button><button @click="decrement(n)">-</button><button @click="incrementOdd(n)">當前求和為奇數再加</button><button @click="incrementWait(n)">等一等再加</button></div>
</template><script>// 引入import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'export default {name:'Count',data() {return {n:1, // 用戶選擇的數字}},computed:{// 借助mapState生成計算屬性,從state中讀取數據(數組寫法)...mapState('countAbout',['sum','school','subject']),...mapState('personAbout',['personList']),// 借助mapGetters生成計算屬性,從getters中讀取數據(數組寫法)...mapGetters('countAbout',['bigSum'])},methods: {// 借助mapMutations生成對應的方法,方法中會調用commit為聯系mutations(對象寫法)...mapMutations('countAbout',{increment:'JIA',decrement:'JIAN'}),// 借助mapActions生成對應的方法,方法中會調用dispatch為聯系actions(對象寫法)...mapActions('countAbout',{incrementOdd:'jiaOdd',incrementWait:'jiaWait'}),},/* mounted() {console.log('Count',this.$store);} */}
</script><style lang="css">button {margin-left: 5px;}
</style>
  • Person.vue改為:
    在這里插入圖片描述
<template><div><h1>人員列表</h1><h3 style="color:red">Count組件求和為:{{sum}}</h3><h3>列表中第一個人的名字是:{{firstPersonName}}</h3><input type="text" placeholder="請輸入名字" v-model="name"><button @click="add">添加</button><button @click="addWang">添加一個姓王的人</button><button @click="addPersonServer">添加一個人,名字隨機</button><ul><li v-for="p in personList" :key="p.id">{{p.name}}</li></ul></div>
</template><script>import {nanoid} from 'nanoid'export default {name:'Person',data(){return {name:''}},computed: {personList() {return this.$store.state.personAbout.personList},sum() {return this.$store.state.countAbout.sum},firstPersonName() {return this.$store.getters['personAbout/firstPersonName']}},methods: {add() {const personObj = {id:nanoid(),name:this.name}// console.log(personObj);this.$store.commit('personAbout/ADD_PERSON',personObj)this.name = '' // 添加完成后 輸入框為空},addWang() {const personObj = {id:nanoid(),name:this.name}this.$store.dispatch('personAbout/addPersonWang',personObj)this.name = '' // 添加完成后 輸入框為空},addPersonServer(){this.$store.dispatch('personAbout/addPersonServer')}},}
</script>

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/209865.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/209865.shtml
英文地址,請注明出處:http://en.pswp.cn/news/209865.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

買賣股票的最佳時機算法(leetcode第121題)

題目描述&#xff1a; 給定一個數組 prices &#xff0c;它的第 i 個元素 prices[i] 表示一支給定股票第 i 天的價格。你只能選擇 某一天 買入這只股票&#xff0c;并選擇在 未來的某一個不同的日子 賣出該股票。設計一個算法來計算你所能獲取的最大利潤。返回你可以從這筆交易…

“HALCON error #2454:HALCON handle was already cleared in operator set_draw“

分析&#xff1a;錯誤提示是窗口句柄已經被刪除&#xff0c;這是因為前邊的一句 HOperatorSet.CloseWindow(hWindowControl1.HalconWindow); 關掉了窗口&#xff0c;屏蔽或刪除即可。

UDS診斷 10服務的肯定響應碼后面跟著一串數據的含義,以及診斷報文格式定義介紹

一、首先看一下10服務的請求報文和肯定響應報文格式 a.診斷儀發送的請求報文格式 b.ECU回復的肯定響應報文格式 c.肯定響應報文中參數定義 二、例程數據解析 a.例程數據 0.000000 1 725 Tx d 8 02 10 03 00 00 00 00 00 0.000806 1 7A5 Rx d 8 06 50 03 00 32 01 F4 CC …

Brushed DC mtr--PIC

PIC use brushed DC mtr fundmental. Low-Cost Bidirectional Brushed DC Motor Control Using the PIC16F684 DC mtr & encoder

《opencv實用探索·八》圖像模糊之均值濾波、高斯濾波的簡單理解

1、前言 什么是噪聲&#xff1f; 該像素與周圍像素的差別非常大&#xff0c;導致從視覺上就能看出該像素無法與周圍像素組成可識別的圖像信息&#xff0c;降低了整個圖像的質量。這種“格格不入”的像素就被稱為圖像的噪聲。如果圖像中的噪聲都是隨機的純黑像素或者純白像素&am…

TailwindCSS 如何設置 placeholder 的樣式

前言 placeholder 在前端多用于 input、textarea 等任何輸入或者文本區域的標簽&#xff0c;它用戶在用戶輸入內容之前顯示一些提示。瀏覽器自帶的 placeholder 樣式可能不符合設計規范&#xff0c;此時就需要通過 css 進行樣式美化。 當項目中使用 TailwindCSS 處理樣式時&a…

JAVA程序如何打jar和war問題解決

背景: 近期研究一個代碼審計工具 需要jar包 jar太多了 可以將jar 打成war包 首先看下程序目錄結構 pom.xml文件內容 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"ht…

Android12 WIFI 無法提供互聯網連接

平臺 RK3588 Android 12 問題描述 ConnectivityService是Android系統中負責處理網絡連接的服務之一。它負責管理設備的網絡連接狀態&#xff0c;包括Wi-Fi、移動數據、藍牙等。 在Android系統中&#xff0c;ConnectivityService提供了一些關鍵功能&#xff0c;包括但不限于…

Spring Boot Async:從入門到精通,原理詳解與最佳實踐

Spring Boot 的異步功能&#xff08;Async&#xff09;允許我們將某些任務異步執行&#xff0c;而不會阻塞主線程。這對于處理耗時的操作非常有用&#xff0c;如發送電子郵件、生成報表、調用外部 API 等。通過異步處理&#xff0c;我們可以釋放主線程&#xff0c;讓它繼續處理…

低多邊形游戲風格3D模型紋理貼圖

在線工具推薦&#xff1a; 3D數字孿生場景編輯器 - GLTF/GLB材質紋理編輯器 - 3D模型在線轉換 - Three.js AI自動紋理開發包 - YOLO 虛幻合成數據生成器 - 三維模型預覽圖生成器 - 3D模型語義搜索引擎 當談到游戲角色的3D模型風格時&#xff0c;有幾種不同的風格&#xf…

區塊鏈實驗室(29) - 關閉或刪除FISCO日志

1. FISCO日志 缺省情況下&#xff0c;FISCO啟動日志模塊&#xff0c;日志記錄的位置在節點目錄中。以FISCO自帶案例為例&#xff0c;4節點的FISCO網絡&#xff0c;24個區塊產生的日志大小&#xff0c;見下圖所示。 2.關閉日志模塊 當節點數量增大&#xff0c;區塊高度增大時&…

總結:服務器批量處理http請求的大致流程

總結&#xff1a;服務器批量處理http請求的大致流程 一客戶端發起請求&#xff1a;可以多個請求同時發送二Web服務器解析請求&#xff08;如&#xff1a;Nginx&#xff09;&#xff1a;可以多個請求同時解析三Servlet容器接收請求&#xff08;如&#xff1a;tomcat&#xff09;…

【EI會議征稿中】第三屆信號處理與通信安全國際學術會議(ICSPCS 2024)

第三屆信號處理與通信安全國際學術會議&#xff08;ICSPCS 2024&#xff09; 2024 3rd International Conference on Signal Processing and Communication Security 信號處理和通信安全是現代信息技術應用的重要領域&#xff0c;近年來這兩個領域的研究相互交叉促進&#xf…

SpringBoot集成Elasticsearch8.x(9)|(RestClient實現Elasticsearch DSL操作)

SpringBoot集成Elasticsearch8.x&#xff08;9&#xff09;|&#xff08;RestClient curl實現Elasticsearch DSL的操作&#xff09; 文章目錄 SpringBoot集成Elasticsearch8.x&#xff08;9&#xff09;|&#xff08;RestClient curl實現Elasticsearch DSL的操作&#xff09;[T…

InsCode:CSDN的創新代碼分享平臺,融合AI技術提升編程體驗

InsCode AI Chat 能夠讓你通過聊天的方式幫你優化代碼。 一&#xff1a;前言 InsCode 是csdn推出的一個代碼分享網站 二、使用 AI 輔助完成代碼 下面我們就從實踐出發&#xff0c;基于 InsCode 的 AI輔助編程&#xff0c;寫Python實現的計算器。 1.基于模板創建項目 這里我…

關于SQL注入問題及解決--小記

1.SQL注入問題 SQL 注入是一種常見的安全漏洞&#xff0c;它發生在應用程序未正確驗證和處理用戶提供的輸入數據時。攻擊者可以通過惡意構造的輸入&#xff0c;將額外的 SQL 代碼注入到應用程序的查詢語句中&#xff0c;從而執行未經授權的數據庫操作。 SQL 注入問題通常出現…

行業地位失守,業績持續失速,科沃斯的故事不好講

特勞特曾在《定位》一書中提到&#xff0c;為了在容量有限的消費者心智中占據品類&#xff0c;品牌最好的差異化就是成為第一&#xff0c;做品類領導者或開創者&#xff0c;銷量遙遙領先&#xff1b;其次分化品類&#xff0c;做到細分品類的唯一&#xff0c;即細分品類的第一。…

Elon Musk艾隆?馬斯克的聊天機器人Grok上線可以使用啦,為X Premium Plus訂閱者推出

艾隆?馬斯克旗下的 AI 初創公司X&#xff08;前身“推特”&#xff09;開發的 ChatGPT 競爭對手 Grok 已經在 X 平臺上正式推出。Grok 是一個基于生成模型 Grok-1的聊天機器人&#xff0c;它能夠回答問題并提供最新的信息。與其他聊天機器人不同&#xff0c;Grok 可以實時獲取…

Java基礎-IDEA下載、卸載、安裝、使用

目錄 1. IDEA下載2. IDEA卸載3. IDEA安裝4. 基本使用 1. IDEA下載 IDEA下載網址 2. IDEA卸載 3. IDEA安裝 更改IDEA安裝目錄 是否創建桌面圖標 下一步 success&#xff01; 4. 基本使用 新建項目 新建模塊 新建包 新建Java文件 編寫代碼 運行測試

2020藍橋杯c組紙張大小

題目名字 紙張大小 題目鏈接 題意 給一張紙&#xff0c;通過不斷折疊&#xff0c;求最終長寬&#xff0c;給十個數字&#xff0c;輸入哪個數字就求哪次折疊的長寬&#xff0c;其實就是&#xff0c;每次折疊后長度的一半變為寬度&#xff0c;原來的寬度變成長度 思路 因為數字…