前端框架Vue3(四)——組件通信及其他API

組件通信

組件關系傳遞方式
父傳子1. props2. v-model3. $refs4. 默認插槽、具名插槽
子傳父1.props2.自定義事件3.v-model4.parent5.作用域插槽
祖傳孫、孫傳祖1.$attrs2.provideinject
兄弟間、任意組件間1.mitt2.pinia

【props】

概述:props是使用頻率最高的一種通信方式,常用與:父<=>子

  • 父傳子:屬性值是非函數
  • 子傳父:屬性值是函數
    父組件:
<template>
<div class="father">
<h3>父組件,</h3>
<h4>我的車:{{car}}</h4>
<h4>兒子給的玩具:{{toy}}</h4>
<Child car="car" getToy="getToy"/>
</div>
</template>
<script setup lang="ts"name="Father">
import Child from './Child.vue
import ref from "vue";
//數據
const car=ref('奔馳')
const toy =ref()
//方法
function getToy(value:string){toy.value=value
}
</script>
<style scoped>
.father{
background-color:rgb(165,164,164);
padding:20px;
border-radius:10px;
}
</style>
<template>
<div class="child">
<h3>子組件</h3>
<h4>玩具:{{ toy }}</h4>
<h5>父給的車:{{ car }}</h5>
<button @click="send">把玩具交給父親</button>
</div>
</template>
<script setup lang="ts" name="Child">import { ref } from 'vue';const toy = ref('奧特曼')defineProps(['car','sendToy'])</script>
<style scoped>
.child{
background-color:skyblue;
padding:10px;
box-shadow:00 10px black;
border-radius:10px;
}
</style>

【custom-event】

<template><div class="father"><h3>父組件</h3><h4 v-show="toy">子給的玩具:{{ toy }}</h4><!--給子組件Child綁定事件  --><Child @send-toy="getToy" /></div>
</template><script setup lang="ts" name="Father">
import { ref } from 'vue';
import Child from './Children.vue';
const toy = ref('奧特曼');
// 接收子組件傳來的 toy
function getToy(value:string){
console.log('父',value)
toy.value = value
}
</script>
<template>
<div class="child">
<h3>子組件</h3>
<h4>玩具:{{ toy }}</h4>
<button @click="emit('send-toy',toy)">點擊</button>
</div>
</template>
<script setup lang="ts" name="ChildEvent">
import { ref } from 'vue'
const toy = ref('奧特曼');
const emit=defineEmits(['send-toy']);
</script>
<style scoped>
.child{
background-color:skyblue;
padding:10px;
box-shadow:00 10px black;
border-radius:10px;
}
</style>

【mitt】

<template><div class="child2"><h3>子組件2</h3><h4>電腦:{{ computer }}</h4><h5>哥哥給的玩具:{{ toy }}</h5></div>
</template><script setup lang="ts" name="Child2">
import emitter from '@/tools/emitter'
import { onUnmounted, ref } from 'vue'const computer = ref('小米')
const toy = ref('')// 給emitter綁定事件
emitter.on('send-toy', (value:unknown) => {if (typeof value === 'string') {toy.value = value}
})onUnmounted(() => {emitter.off('send-toy')
})
</script>
<template>
<div class="child1">
<h3>子組件1</h3>
<h4>玩具:{{ toy }}</h4>
<button @click="emitter.emit('send-toy',toy)">玩具給弟弟</button>
</div>
</template>
<script setup lang="ts" name='Child1'>
import emitter from '@/tools/emitter';
import { ref } from 'vue'const toy=ref('奧特曼')
</script>

【v-model】

<template><div class="father"><h3>父組件</h3><h4>{{ username }}</h4><!-- v-model用在html標簽上 --><!-- <input type="text" v-model="username"> --><!-- <input type="text" :value="username" @input="username = (<HTMLInputElement>$event.target).value"> --><!-- v-model用在組件標簽上 --><HISTInput v-model="username"></HISTInput><!--  <HISTInput:modelValue="username"@update:modelValue="username=$event"></HISTInput> --></div>
</template>
<template><input type="text":value="modelValue"@input="emit('update:modelValue', (<HTMLInputElement>$event.target).value)">
</template><script setup lang="ts" name="HISTInput">
defineProps(['modelValue'])
const emit=defineEmits(['update:modelValue'])
</script>

【$attrs】

  1. 概述:$attrs用于實現當前組件的父組件,向當前組件的子組件通信**(祖一孫)**。
  2. 具體說明:$attrs是一個對象,包含所有父組件傳入的標簽屬性。

注意:$attrs會自動排除props中聲明的屬性(可以認為聲明過的props被子組件自己“消費”了)

<template><div></div>
</template><script setup lang="ts" name="GrandChild"></script><style lang="scss" scoped></style>
<template><div class="Child"><h3>孫組件</h3><h4>a:{{ a }}</h4><h4>b:{{ b }}</h4><h4>]c:{{ c }}</h4><h4>d:{{ d }}</h4><h4>x:{{ x }}</h4><h4>y:{{ y }}</h4><h4>z:{{ z }}</h4><button @click="updateA(6)">點我加6</button><GrandChild v-bind="$attrs" /></div>
</template><script setup lang="ts" name="Child">
import GrandChild from './GrandChild.vue';
defineProps(['a','b','c','d','x','y','z','updateA'])
</script><style lang="scss" scoped></style>
<template><div class="father"><h3>父組件</h3><h4>a:{{ a }}</h4><h4>b:{{ b }}</h4><h4>c:{{ c }}</h4><h4>d:{{ d }}</h4><Child :a="a" :b="b" :c="c" :d="d" v-bind="{x:100,y:200}" :updateA="updateA"/></div>
</template><script setup lang="ts" name="Father">
import Child from './ChildPractice.vue'
import { ref } from 'vue'const a=ref(1)
const b=ref(2)
const c=ref(3)
const d=ref(4)
function updateA(value:number){a.value=value
}
</script><style lang="scss" scoped></style>

refs、refs、refsparent】

  1. 概述:
    • $refs用于:父→子。
    • $parent用于:子一父。
  2. 原理如下:
屬性說明
$refs值為對象,包含所有被ref屬性標識的D0M元素或組件實例。
$parent值為對象,當前組件的父組件實例對象。
<template><div class="father"><h2>父組件</h2><h4>房產:{{ house }}</h4><button @click="changeToy">修改Child1的玩具</button><button @click="changeComputer">修改Child1的玩具</button><button @click="getAllChild($refs)">獲取所有的子組件實例對象</button><Child1 ref="c1"></Child1><Child2></Child2></div>
</template><script setup lang="ts" name="FatherPractice">
import { ref } from 'vue';
import Child1 from './Child1Practice.vue';
import Child2 from './Child2Practice.vue';//注意點:當訪問obj.c的時候,底層會自動讀取value屬性,因為c是在obj這個對象中的
/*let obj= reactive({
a:1,
b:2,
c:ref(3)
})
let x =ref(4)
console.log(obj.a)
console.log(obj.b)
console.log(obj.c)
console.log(x)*/
const house = ref(4);
const c1=ref()
function changeToy() {c1.value.a('小牛牛')
}
function changeComputer() {c1.value.b('redmi')
}
function getAllChild(refs:any) {for (const key in refs) {refs[key].b+=3}
}
defineExpose({house
})
</script><style scoped></style>
<template><div class="child1-practice"><h3>子組件1</h3><h4>a:{{ a }}</h4><h4>b:{{ b }}</h4><button @click="minusHouse($parent)">干掉父親的一套房產</button></div>
</template><script setup lang="ts" name="Child1Practice">
import { ref } from 'vue'
const a = ref(1)
const b = ref(2)
defineExpose({a,b
})function minusHouse (parent:any) {parent.house-=1
}
</script><style scoped></style>
<template><div class="child2-practice"><h2>子組件2</h2><h4>a:{{ a }}</h4><h4>b:{{ b }}</h4></div>
</template><script setup lang="ts" name="Child2Practice">
import { ref } from 'vue';
const a = ref(1)
const b = ref(2)
</script><style scoped></style>

【provide、inject】

  1. 概述:實現祖孫組件直接通信
  2. 具體使用
    • 在祖先組件中通過provide配置向后代組件提供數據
    • 在后代組件中通過inject配置來聲明接收數據
<template><div class="Child"><h3>孫組件</h3><h4>a:{{ a }}</h4><h4>b:{{ b }}</h4><h4>]c:{{ c }}</h4><h4>d:{{ d }}</h4><h4>x:{{ x }}</h4><h4>y:{{ y }}</h4><h4>z:{{ z }}</h4><button @click="updateA(6)">點我加6</button><GrandChild v-bind="$attrs" /></div>
</template><script setup lang="ts" name="Child">
import GrandChild from './GrandChild.vue';
defineProps(['a','b','c','d','x','y','z','updateA'])
</script><style lang="scss" scoped></style>
<template><div class="father"><h3>父組件</h3><h4>銀子:{{ money }}</h4><h4>車子:{{ car.name }},價值:{{ car.price }}</h4><Child /></div>
</template><script setup lang="ts" name="Father">
import { provide, reactive, ref } from 'vue'
import Child from './ChildPractice.vue'
const money=ref(1000)
const car=reactive({name:'保時捷',price:100000
})
function changeMoney(value:number){money.value-=value
}
// 向后代提供數據
provide('moneyContext',{money:money.value,changeMoney})
provide('car',car)
</script><style lang="scss" scoped></style>
<template><div class="grand-child"><h3>孫組件</h3><h4>銀子:{{money}}</h4><h4>車子:{{ car.brand }},價值{{car.price}}萬元</h4><button @click="updateMoney(6)">花錢</button></div>
</template><script setup lang="ts" name="GrandChild">import { inject } from 'vue';const {money,updateMoney}=inject('moneyContext',{money:0,updateMoney:(_:number)=>{}})const car=inject('car',{brand:'未知',price:1000})
</script><style lang="scss" scoped></style>

【slot】

<template><div class="father-practice"><h3>父組件</h3><div class="content"><Category><template v-slot:s2><ul><li v-for="item in games" :key="item.id">{{ item.name }}</li></ul></template><template v-slot:s1><h2>熱門游戲列表</h2></template></Category><Category><template v-slot:s2><img :src=imgUrl alt=""></template><template v-slot:s1><h2>今日美食城市</h2></template></Category><Category><template v-slot:s1><video :src="videoUrl"></video></template><template v-slot:s2><h2>近日影視推薦</h2></template></Category></div></div>
</template><script setup lang="ts" name="father-practice">
import { reactive, ref } from 'vue';
import Category from './CategoryPractice.vue';
const games=reactive([{id:1,name:'英雄聯盟'},{id:2,name:'王者榮耀'},{id:3,name:'和平精英'},{id:4,name:'穿越火線'},
])
const imgUrl=ref('https://z1.ax1x.com/2023/11/19/piNxLo4.jpg')
const videoUrl=ref('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4')</script><style scoped>
.father{
background-color:rgb(165,164,164);
padding:20px;
border-radius:10px;
}.content{
display:flex;
justify-content: space-evenly;
}
</style>
<template><div class="category">
<slot names="s1">默認內容1</slot>
<slot name="s2">默認內容2</slot>
</div>
</template><script setup lang="ts" name="CategoryPractice"></script><style scoped>
.category-practice {
background-color: skyblue;
}</style>

其他API

【shallowRef與shallowReactive】

shallowRef
  1. 作用:創建一個響應式數據,但只對頂層屬性進行響應式處理。
  2. 用法:
    let =myVar shallowRef(initialValue);
  3. 特點:只跟蹤引用值的變化,不關心值內部的屬性變化。
shallowReactive
  1. 作用:創建一個淺層響應式對象,只會使對象的最頂層屬性變成響應式的,對象內部的嵌套屬性則不會變成
    響應式的
  2. 用法:
    const =myobj shallowReactive({...})
  3. 特點:對象的頂層屬性是響應式的,但嵌套對象的屬性不是。

通過使用shallowRef()shallowReactive()來繞開深度響應。淺層式API創建的狀態只在其頂層是
響應式的對所有深層的對象不會做任何處理,避免了對每一個內部屬性做響應式所帶來的性能成本,
這使得屬性的訪問變得更快,可提升性能。

<template><div class="App">
<h2>求和:{{ sum }}</h2>
<h2>姓名:{{ person.name }}</h2>
<h2>年齡:{{ person.age }}</h2>
<h2>車:{{ car.brand }}</h2>
<button @click="changeSum">sum+1</button>
<button @click="changeName">修改名字</button>
<button @click="changeAge">修改年齡</button>
<button @click="changePerson">修改整個人</button>
<button @click="changeBrand">修改品牌</button>
<button @click="changeColor">修改顏色</button>
<button @click="changeEngine">修改發動機</button>
<button @click="changeCar">修改整個車</button>
</div>
</template><script setup lang="ts" name="App">
import {  ref, shallowRef,shallowReactive } from 'vue'
const sum=shallowRef(0)
const person=ref({name:'張三',age:18})
// const car =reactive({
// brand:'奔馳',
// options:{
// color:'紅色',
// engine:''
// }
// })
const car =shallowReactive({
brand:'奔馳',
options:{
color:'紅色',
engine:''
}
})
function changeSum(){sum.value+=1
}
function changeName (){person.value.name='李四'
}function changeAge (){person.value.age =60
}function changePerson (){person.value={name:'王五',age:19}
}
function changeBrand(){
car.brand='寶馬'
}
function changeColor(){
car.options.color='紫色'
}
function changeEngine(){
car.options.engine ='V12'
}
function changeCar(){
Object.assign(car)
}
</script><style scoped>
.App{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;
}
button{margin:0 5px;
}
</style>

【readonly與shallowReadonly】

readonly
  1. 作用:用于創建一個對象的深只讀副本。
  2. 用法:
    const original reactive({...}) const readOnlyCopy= readonly(original);
  3. 特點
    • 對象的所有嵌套屬性都將變為只讀。
    • 任何嘗試修改這個對象的操作都會被阻止(在開發模式下,還會在控制臺中發出警告)。
  4. 應用場景:
    • 創建不可變的狀態快照。
    • 保護全局狀態或配置不被修改。
shallowReadonly
  1. 作用:與readonly類似,但只作用于對象的頂層屬性。
  2. 用法:
    const original reactive({...}) const shallowReadOnlyCopy shallowReadonly(original);
  3. 特點:
    • 只將對象的頂層屬性設置為只讀,對象內部的嵌套屬性仍然是可變的。
    • 適用于只需保護對象頂層屬性的場景。
<template><div class="app">
<h2>當前sum求和為:{{sum}}</h2>
<h2>當前sum2求和為:{{sum2}}</h2>
<h2>當前汽車為:{{car}}</h2>
<h2>當前汽車為:{{car2}}</h2>
<button @click="changeSum">sum1+1</button>
<button @click="changeSum2">sum2+1</button>
<button @click="changeBrand">修改品牌</button>
<button @click="changeBrand2">修改品牌</button>
<button @click="changeColor">修改顏色</button>
<button @click="changePrice">修改價格</button>
<button @click="changeColor2">修改顏色</button>
<button @click="changePrice2">修改價格</button>
</div>
</template><script setup lang="ts" name="App">
import { reactive, readonly, ref, shallowReadonly } from 'vue'
const sum = ref(0)
const sum2=readonly(()=>sum.value+1)
const car=reactive({brand:'audi',options:{color:'red',price:100000}
})
function changeSum(){sum.value+=1
}
const car2=shallowReadonly(car)
function changeSum2(){sum2.value+=1
}
function changeColor(){car.options.color='blue'
}
function changePrice(){car.options.price+=10
}
function changeBrand(){car.brand='hongqi'
}
function changeBrand2(){car2.brand='hongqi'
}
function changeColor2(){car.options.color='blue'
}
function changePrice2(){car.options.price+=10
}
</script><style scoped>
.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;
}
button{margin:0 5px;
}
</style>

【toRaw與markRaw】

toRaw
  1. 作用:用于獲取一個響應式對象的原始對象,toRaw返回的對象不再是響應式的,不會觸發視圖更新

官網描述:這是一個可以用于臨時讀取而不引起代理訪問/跟蹤開銷,或是寫入而不觸發更改的特殊方
法。不建議保存對原始對象的持久引用,請謹慎使用。
何時使用?一一在需要將響應式對象傳遞給非Vue的庫或外部系統時,使用toRaw可以確保它們收
到的是普通對象

  1. 具體編碼:
import {reactive,toRaw,markRaw,isReactive} from "vue";
//toRaw 
//響應式對象
let person =reactive({name:tony',age:18))
//原始對象
let rawPerson =toRaw(person)
//markRaw 
let citysd markRaw([
{id:'asdda01',name:'北京'}{id:'asdda02',name:'上海'}{id:'asdda3',name:'天津'}{"name":"重慶","id":"asdda04"}
])
//根據原始對象citys去創建響應式對象citys2--創建失敗,因為citys被markRaw標記了
let citys2 =reactive(citys)
console.log(isReactive(person))
console.log(isReactive(rawPerson))
console.log(isReactive(citys))
console.log(isReactive(citys2))
markRaw
  1. 作用:標記一個對象,使其永遠不會變成響應式的。

例如使用mockjs時,為了防止誤把mockjs變為響應式對象,可以使用markRaw去標記mockjs

  1. 編碼:
//markRaw 
let citys= markRaw([
{id:'asdda01',name:'北京'}{id:'asdda02',name:'上海'}{id:'asdda03',name:'天津'}{id:"asdda04",name:"重慶"}
])
//根據原始對象citys去創建響應式對象citys2--創建失敗,因為citys被markRaw標記了
let citys2 =reactive(citys)

【customRef】

作用:創建一個自定義的ref,并對其依賴項跟蹤和更新觸發進行邏輯控制。
實現防抖效果(useSumRef.ts):

import {customRef from "vue";
export default function(initValue:string,delay:number){
let msg= customRef((track,trigger)=>{
let timer:number
return{
get(){
track()//告訴Vue數據msg很重要,要對msg持續關注,一旦變化就更新
return initValue
},
set(value){
clearTimeout(timer)
timer =setTimeout(()=>
initValue =value
trigger()//通知Vue數據msg變化了
}delay);
}
}
})

provide與inject

  • 作用:實現祖孫組件間通信
  • 套路:父組件有一個
    provide選項來提供數據,子組件有一個inject選項來開始使用這些數據
  • 具體寫法:
    1. 祖組件中:
    setup(){......let car=reactive({name:'奔馳',price:'4o萬'})provide('car',car)......}
    
    1. 孫組件中:
setup(props,context){const car =inject('car')return {car}}

響應式數據的判斷

  • isRef:檢查一個值是否為一個ref對象
  • isReactive:檢查一個對象是否是由reactive:創建的響應式代理
  • isReadonly:檢查一個對象是否是由readonly:創建的只讀代理
  • isProxy:檢查一個對象具否是由reactive或者readonly方法創建的代理

Fragment

  • 在Vue2中:組件必須有一個根標簽
  • 在Vue3中:組件可以沒有根標簽,內部會將多個標簽包含在一個Fragment虛擬元素中
  • 好處:減少標簽層級,減小內存占用

【Teleport】

  • 什么是Teleport?一一Teleport是一種能夠將我們的組件html結構移動到指定位置的技術。
<teleport to='body'>
<div class="modal" v-show="isShow">
<h2>我是一個彈窗</h2>
<p>我是彈窗中的一些內容</p>
<button @click="isShow=false">關閉彈窗</button>
</div>
</teleport>

【Suspense】

  • 等待異步組件時渲染一些額外內容,讓應用有更好的用戶體驗
  • 使用步驟:
    • 異步引入組件
    • 使用Suspense包裹組件,并配置好defaultfallback
import defineAsyncComponent,Suspense from "vue";
const Child =defineAsyncComponent(()=>import('./Child.vue'))
<template>
<div class="app">
<h3>我是App組件</h3>
<Suspense>
<template v-slot:default>
<Child/>
</template>
<template v-slot:fallback>
<h3>加載中.....</h3>
</template>
</Suspense>
</div>
</template>

【全局API轉移到應用對象】

  • app.component
  • app.config
  • app.directive
  • app.mount
  • app.unmount
  • app.use

【其他】

  • 過渡類名v-enter修改為v-enter-from、過渡類名v-leave修改為v-leave-from
  • keyCode作為v-on修飾符的支持。
  • v-model指令在組件上的使用已經被重新設計,替換掉了v-bind.sync
  • v-ifv-for在同一個元素身上使用時的優先級發生了變化。
  • 移除了$on$off$once實例方法。
  • 移除了過濾器filter
  • 移除了$children實例propert

Composition API的優勢

  1. Options API存在的問題
    使用傳統OptionsAPI中,新增或者修改一個需求,就需要分別在data,methods,computed.里修改。
  2. Composition API的優勢
    我們可以更加優雅的組織我們的代碼,函數。讓相關功能的代碼更加有序的組織在一起。

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

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

相關文章

07【C++ 初階】類和對象(中篇) --- 類的默認成員函數

文章目錄前言類的6個默認成員函數1.構造函數1.1 構造函數特性1.1.1 函數名與類名相同1.1.2 無返回值1.1.3 對象實例化時編譯器自動調用對應的構造函數1.1.4 構造函數可以重載1.1.5 默認構造只能有一個1.1.6 默認構造的必要性1.2 構造函數的初始化列表2.析構函數2.1 析構函數特性…

第二次CISSP考試通過!

今天我終于臨時通過了 CISSP 考試&#xff01;這第二次的精神壓力一點也不比第一次小。我在第 101 道題 時通過&#xff0c;還剩大約 30 分鐘。我當時真的以為自己又要像上次那樣時間不夠了。第一次考試的失敗經歷&#xff1a;第一次考試是我剛參加完為期 5 天的強化 Boot Camp…

USRP捕獲手機/路由器數據傳輸信號波形(上)

目錄&#xff1a; USRP捕獲手機/路由器數據傳輸信號波形&#xff08;上&#xff09; USRP捕獲手機/路由器數據傳輸信號波形&#xff08;中&#xff09; USRP捕獲手機/路由器數據傳輸信號波形&#xff08;下&#xff09; 一、前期準備 1.1 場景與系統 手機、路由器與天線的…

基于STM32F103的FM1702驅動程序

基于STM32F103微控制器與復旦微電子FM1702SL射頻讀卡芯片的驅動開發方案&#xff0c;整合了硬件配置、寄存器操作和通信協議實現&#xff1a;一、硬件連接設計 1. 管腳映射表FM1702SL引腳STM32F103引腳功能說明VDD3.3V電源輸入GNDGND地線SCKPA5(SPI1_SCK)SPI時鐘MISOPA6(SPI1_M…

京東商品評論API指南

一、引言京東商品評論API(JD.item_review)是京東開放平臺提供的重要接口&#xff0c;允許開發者獲取商品的詳細評論數據。通過該接口可以獲取包括評論內容、評分、評論時間、用戶昵稱等信息&#xff0c;為商品分析、用戶行為研究等提供數據支持?。二、接口概述1. 接口基本信息…

網絡編程概述與UDP編程

一、 網絡編程概述 1.1 概述 在現代軟件開發與系統交互場景里&#xff0c;基于 Socket 的網絡多進程通信占據核心地位&#xff0c;其適用場景廣泛且深入到各類數字化交互中&#xff1a; 直播場景&#xff1a;主播端通過 Socket 建立的網絡連接&#xff0c;將音視頻流以數據包…

新手教程:用外部 PostgreSQL 和 Zookeeper 啟動 Dolphinscheduler

本文將帶你一步步通過外部PostgreSQL和Zookeeper來啟動Apache DolphinScheduler。無論你是新手還是有經驗的開發者&#xff0c;都能輕松跟著這些步驟在Linux/Unix環境中完成安裝和配置。除了常見的安裝步驟&#xff0c;我們還會分享一些集群部署的技巧&#xff0c;讓你輕松擴展…

安寶特案例丨AR+AI賦能軌道交通制造:破解人工裝配難題的創新實踐

在軌道交通裝備制造領域&#xff0c;小批量、多品種的生產特性與高度依賴人工經驗的作業模式長期并存&#xff0c;導致效率瓶頸與質量隱患并存。安寶特通過AR&#xff08;增強現實&#xff09;AI&#xff08;人工智能&#xff09;技術融合&#xff0c;在螺栓緊固、內飾裝配、制…

基于LSTM-GRU混合網絡的動態解析:美聯儲維穩政策與黃金單日跌1.5%的非線性關聯

摘要&#xff1a;本文通過構建多因子量化模型&#xff0c;結合自然語言處理&#xff08;NLP&#xff09;技術對美聯儲政策文本進行情緒分析&#xff0c;解析經濟數據、市場情緒及宏觀環境對黃金價格的復合影響機制。研究基于LSTM時間序列預測框架&#xff0c;驗證關鍵事件對金價…

RabbitMQ消息確認機制有幾個confirm?

RabbitMQ 的消息確認機制中&#xff0c;“confirm” 這個詞主要出現在兩個關鍵環節&#xff0c;對應兩種確認&#xff1a;? 兩種 confirm&#xff08;確認&#xff09;機制確認類型觸發方說明Publisher Confirm&#xff08;生產者確認&#xff09;生產者 → Broker消息是否成功…

vue項目啟動時因內存不足啟動失敗

可以使用increase-memory-limit跟npm install cross-env插件npm install increase-memory-limit npm install cross-env安裝后需要在package.json文件中加入如下代碼"scripts": {"fix-memory-limit": "cross-env LIMIT3072 increase-memory-limit&quo…

WEditor:高效的移動端UI自動化腳本可視化編輯器

WEditor&#xff1a;高效的移動端UI自動化腳本可視化編輯器前言一、核心特性與優勢1. 可視化操作&#xff0c;降低門檻2. 跨平臺支持3. 豐富的控件層級展示4. 快捷鍵高效操作5. 開源可擴展二、安裝與環境配置1. 環境準備Android 設備用戶需額外準備ADB 安裝與配置步驟2. 安裝依…

面試高頻題 力扣 283.移動零 雙指針技巧 原地修改 順序保持 C++解題思路 每日一題

目錄零、題目描述一、為什么這道題值得你花幾分鐘看懂&#xff1f;二、題目拆解&#xff1a;提取其中的關鍵點三、明確思路&#xff1a;雙指針的巧妙配合四、算法實現&#xff1a;雙指針的代碼演繹五、C代碼實現&#xff1a;一步步拆解代碼拆解時間復雜度和空間復雜度六、實現過…

arrch64架構下調用pyvista報錯

arrch64架構下調用pyvista報錯 問題 python編程使用到了pyvista&#xff0c;使用conda新建了環境&#xff0c;但是使用的時候報錯 Traceback (most recent call last):File "/home/ztl/MGGBSAR/src/trans_las_3D.py", line 16, in <module>import pyvista as p…

功能強大編輯器

時間限制&#xff1a;1秒 內存限制&#xff1a;128M題目描述你要幫助小可創造一個超級數字編輯器&#xff01;編輯器依舊運行在Linux下&#xff0c;因此你只能通過指令去操控他。指令有五種&#xff1a; In X 表示在光標左側插入一個數字 Del 表示刪除光標左側一個數字 …

【力扣】面試經典150題總結01-數組/字符串

1.合并兩個有序數組&#xff08;簡單&#xff09;要求直接在num1上操作&#xff0c;已經預留了空間&#xff0c;所以直接倒著從大到小插入。當其中一個數組遍歷完&#xff0c;就把另一個數組剩余的部分插入。2.移除元素&#xff08;簡單&#xff09;要求原地移除數組中所有val元…

基于 Hadoop 生態圈的數據倉庫實踐 —— OLAP 與數據可視化(一)

目錄 一、OLAP 與 Impala 簡介 1. OLAP 簡介 2. Impala 簡介 &#xff08;1&#xff09;Impala 是什么 &#xff08;2&#xff09;為什么要使用 Impala &#xff08;3&#xff09;適合 Impala 的使用場景 &#xff08;4&#xff09;Impala 架構 &#xff08;5&#xff…

PyTorch L2范數詳解與應用

torch.norm 是什么 torch.norm(dot_product, p=2, dim=-1) 是 PyTorch 中用于計算張量 L2 范數的函數, 1. 各參數解析 dot_product:輸入張量,在代碼中形狀為 [batch_size, seq_len](每個元素是 token 隱藏狀態與關注向量的點積)。 p=2:指定計算L2 范數(歐幾里得范數)…

循環神經網絡RNN原理精講,詳細舉例!

第一部分&#xff1a;為什么需要RNN&#xff1f;在了解RNN是什么之前&#xff0c;我們先要明白它解決了什么問題。傳統的神經網絡&#xff0c;比如我們常見的前饋神經網絡&#xff08;Feedforward Neural Network&#xff09;或者卷積神經網絡&#xff08;CNN&#xff09;&…

如何用USRP捕獲手機信號波形(中)手機/基站通信

目錄&#xff1a; 如何用USRP捕獲手機信號波形&#xff08;上&#xff09;系統及知識準備 如何用USRP捕獲手機信號波形&#xff08;中&#xff09;手機/基站通信 如何用USRP捕獲手機信號波形&#xff08;下&#xff09;協議分析 四、信號捕獲結果 4.1 時域波形 我懷疑下面…