最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue組件通信全場景詳解(新手也能看懂)

 更新時間:2026年04月17日 08:50:17   作者:前端那點事  
Vue?組件通信是前端開發(fā)核心知識點,不同組件層級對應不同的通信方案,本文將按基礎場景,進階場景,特殊場景進行系統(tǒng)梳理,希望對大家有所幫助

Vue 組件通信是前端開發(fā)核心知識點,不同組件層級(父子、兄弟、跨級)對應不同的通信方案,核心原則是:簡潔、高效、貼合場景,避免過度復雜的通信邏輯。以下按「基礎場景→進階場景→特殊場景」梳理,結合實戰(zhàn)常用方式,覆蓋 Vue2、Vue3 通用用法,附實戰(zhàn)示例,直接適配項目開發(fā)。

一、基礎場景:父子組件通信(最常用)

父子組件是最常見的組件關系(如父組件嵌套子組件),通信方式簡單直接,Vue 原生支持,無需額外依賴,以下涵蓋所有父子通信相關方式。

1. 父傳子:Props

核心:父組件通過自定義屬性向子組件傳遞數(shù)據(jù),子組件通過 props 接收,單向數(shù)據(jù)流(父變子變,子不能直接修改 props),是父子通信最基礎、最常用的方式,耳熟能詳,無需過多冗余說明。

// 父組件 Parent.vue
<template>
  <!-- 傳遞普通值、對象、方法 -->
  <Child 
    :name="userName" 
    :user="userInfo" 
    :handleClick="parentClick"
  />
</template>

<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const userName = ref('張三')
const userInfo = ref({ age: 22, role: 'admin' })
const parentClick = () => {
  console.log('父組件方法被調(diào)用')
}
</script>

// 子組件 Child.vue
<template>
  <div>{{ name }} - {{ user.age }}</div>
  <button @click="handleClick">調(diào)用父組件方法</button>
</template>

<script setup>
// 接收父組件傳遞的數(shù)據(jù),可指定類型、默認值、校驗
const props = defineProps({
  name: {
    type: String,
    required: true, // 必傳
    default: '未知用戶'
  },
  user: {
    type: Object,
    default: () => ({}) // 對象默認值需用函數(shù)
  },
  handleClick: {
    type: Function
  }
})
</script>

注意:子組件若需修改 props,需通過「子傳父」通知父組件修改,避免直接修改 props 破壞單向數(shù)據(jù)流。

2. 父傳子:$refs

核心:若用在普通 DOM 元素上,引用指向該 DOM 元素;若用在子組件上,引用指向子組件實例,父組件可通過 $refs.xx 主動獲取子組件的屬性、調(diào)用子組件的方法,靈活高效。

// 父組件 Parent.vue
<template>
  <Child ref="childRef" />
  <button @click="operateChild">操作子組件</button>
  <div ref="domRef">普通DOM元素</div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Child from './Child.vue'

const childRef = ref(null) // 綁定子組件ref
const domRef = ref(null) // 綁定普通DOM元素

onMounted(() => {
  // 訪問普通DOM元素
  console.log(domRef.value.textContent) // 輸出:普通DOM元素
})

const operateChild = () => {
  // 訪問子組件數(shù)據(jù)
  console.log(childRef.value.childName)
  // 調(diào)用子組件方法
  childRef.value.childMethod()
}
</script>

// 子組件 Child.vue
<script setup>
import { ref } from 'vue'

const childName = ref('子組件')
const childMethod = () => {
  console.log('子組件方法被調(diào)用')
}

// Vue3 setup 需主動暴露,父組件才能訪問
defineExpose({
  childName,
  childMethod
})
</script>

3. 父傳子:$children

核心:父組件通過 $children 獲取一個包含所有直接子組件(不包含孫子組件)的 VueComponent 對象數(shù)組,可直接訪問子組件中所有數(shù)據(jù)和方法,適合批量操作子組件的場景。

// 父組件 Parent.vue
<template>
  <Child1 />
  <Child2 />
  <button @click="operateAllChildren">操作所有子組件</button>
</template>

<script>
// Vue2 用法(Vue3 setup 中需通過 getCurrentInstance 獲?。?
import Child1 from './Child1.vue'
import Child2 from './Child2.vue'

export default {
  components: { Child1, Child2 },
  methods: {
    operateAllChildren() {
      // 獲取所有直接子組件,遍歷操作
      this.$children.forEach(child => {
        console.log(child.childName) // 訪問子組件數(shù)據(jù)
        child.childMethod() // 調(diào)用子組件方法
      })
    }
  }
}

// Vue3 setup 用法
import { getCurrentInstance } from 'vue'
import Child1 from './Child1.vue'
import Child2 from './Child2.vue'

const instance = getCurrentInstance()
const operateAllChildren = () => {
  instance.refs.$children.forEach(child => {
    console.log(child.childName)
    child.childMethod()
  })
}
</script>

4. 父子雙向綁定:.sync 修飾符

核心:可實現(xiàn)父組件向子組件傳遞數(shù)據(jù)的雙向綁定,子組件接收到數(shù)據(jù)后可直接修改,且會同步修改父組件中的數(shù)據(jù),簡化雙向通信代碼,與 v-model 功能類似但適用場景更靈活。

// 父組件 Parent.vue
<template>
  <!-- .sync 修飾符實現(xiàn)雙向綁定 -->
  <Child :count.sync="parentCount" />
  <p>父組件count:{{ parentCount }}</p>
</template>

<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const parentCount = ref(0)
</script>

// 子組件 Child.vue
<template>
  <button @click="changeCount">修改count(.sync)</button>
</template>

<script setup>
const props = defineProps(['count'])
const emit = defineEmits(['update:count'])

const changeCount = () => {
  // 觸發(fā) update:屬性名 事件,實現(xiàn)雙向同步
  emit('update:count', props.count + 1)
}
</script>

5. 父子雙向綁定:v-model

核心:和 .sync 類似,可實現(xiàn)父組件傳給子組件的數(shù)據(jù)雙向綁定,本質(zhì)是 props + emit 的語法糖,子組件通過 emit 修改父組件的數(shù)據(jù),更適合表單類、開關類組件場景。

// 子組件 Child.vue(表單組件)
<template>
  <input 
    type="text" 
    :value="modelValue" 
    @input="emit('update:modelValue', $event.target.value)"
  />
</template>

<script setup>
// v-model 默認綁定 modelValue,觸發(fā) update:modelValue 事件
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
</script>

// 父組件 Parent.vue
<template>
  <!-- 雙向綁定,無需額外監(jiān)聽事件 -->
  <Child v-model="inputValue" />
  <p>父組件接收值:{{ inputValue }}</p>
</template>

<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const inputValue = ref('')
</script>

6. 父傳子:插槽(默認插槽、具名插槽)

核心:父組件通過插槽向子組件傳遞 HTML 模板、組件,實現(xiàn)“內(nèi)容分發(fā)”,本質(zhì)是父向子的通信,適合組件封裝(如彈窗、卡片),分為默認插槽和具名插槽,滿足不同內(nèi)容分發(fā)需求。

// 子組件 Child.vue(插槽組件)
<template>
  <div class="card">
    <!-- 匿名插槽:接收父組件傳遞的任意內(nèi)容,無名稱 -->
    <slot>默認內(nèi)容(父組件未傳內(nèi)容時顯示)</slot>
    
    <!-- 具名插槽:接收指定名稱的內(nèi)容,實現(xiàn)多區(qū)域分發(fā) -->
    <slot name="header">默認頭部</slot>
    <slot name="footer">默認底部</slot>
  </div>
</template>

// 父組件 Parent.vue
<template>
  <Child>
    <!-- 匿名插槽內(nèi)容 -->
    <p>卡片主體內(nèi)容</p>
    
    <!-- 具名插槽內(nèi)容,通過 # 簡寫指定插槽名稱 -->
    <template #header>
      <h3>卡片標題</h3>
    </template>
    
    <template #footer>
      <button>點擊按鈕</button>
    </template>
  </Child>
</template>

7. 子傳父:$emit / v-on

核心:子組件通過派發(fā)自定義事件的方式,向父組件傳遞數(shù)據(jù),或觸發(fā)父組件的更新等操作,父組件通過 v-on 監(jiān)聽事件接收數(shù)據(jù),是子傳父最核心、最常用的方式。

// 子組件 Child.vue
<template>
  <button @click="sendData">向父組件傳值</button>
</template>

<script setup>
// 定義可觸發(fā)的自定義事件
const emit = defineEmits(['sendMsg', 'updateName'])

const sendData = () => {
  // 觸發(fā)事件,可傳遞1個或多個參數(shù)
  emit('sendMsg', '子組件傳遞的消息', 123)
  emit('updateName', '李四') // 通知父組件修改名稱
}
</script>

// 父組件 Parent.vue
<template>
  <Child 
    @sendMsg="getMsg" 
    @updateName="userName = $event"
  />
</template>

<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const userName = ref('張三')
const getMsg = (msg, num) => {
  console.log('接收子組件消息:', msg, num) // 輸出:子組件傳遞的消息 123
}
</script>

8. 子傳父:$parent

核心:子組件通過 $parent 獲取父節(jié)點的 VueComponent 對象,包含父節(jié)點中所有數(shù)據(jù)和方法,可直接訪問父組件的屬性、調(diào)用父組件的方法,實現(xiàn)子向父的通信。

// 父組件 Parent.vue
<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const parentName = ref('父組件')
const parentMethod = () => {
  console.log('父組件方法被調(diào)用')
}

// Vue3 setup 需暴露給子組件
defineExpose({
  parentName,
  parentMethod
})
</script>

// 子組件 Child.vue
<template>
  <button @click="accessParent">訪問父組件</button>
</template>

<script setup>
import { getCurrentInstance } from 'vue'

const instance = getCurrentInstance()
const accessParent = () => {
  // 訪問父組件數(shù)據(jù)
  console.log(instance.parent.parentName)
  // 調(diào)用父組件方法
  instance.parent.parentMethod()
}
</script>

9. 子傳父:插槽(作用域插槽)

核心:作用域插槽是子傳父的特殊形式,子組件通過插槽向父組件傳遞數(shù)據(jù),父組件接收數(shù)據(jù)后,可根據(jù)數(shù)據(jù)自定義插槽內(nèi)容,實現(xiàn)“子傳數(shù)據(jù)、父定義渲染”的靈活通信。

// 子組件 Child.vue(作用域插槽)
<template>
  <div>
    <!-- 子組件向父組件傳遞數(shù)據(jù)(row、index) -->
    <slot :row="user" :index="1">
      默認內(nèi)容(父組件未自定義插槽時顯示)
    </slot>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const user = ref({ name: '張三', age: 22 })
</script>

// 父組件 Parent.vue
<template>
  <Child>
    <!-- 父組件接收子組件傳遞的數(shù)據(jù),自定義渲染內(nèi)容 -->
    <template #default="slotProps">
      <p>姓名:{{ slotProps.row.name }}</p>
      <p>索引:{{ slotProps.index }}</p>
    </template>
  </Child>
</template>

二、進階場景:兄弟組件/跨級組件通信

當組件層級超過2層(如爺爺→父→子),或無直接關系(兄弟組件),使用父子通信會導致代碼冗余,需用進階方案,以下補充完善跨級、兄弟通信的所有常用方式。

1. 兄弟組件通信:事件總線(EventBus)

核心:通過一個空的 Vue 實例作為中央事件總線(事件中心),不管是父子組件、兄弟組件、跨層級組件等,都可以通過它完成通信操作,適合中小型項目。

// 1. 創(chuàng)建事件總線(utils/eventBus.js)
import { ref, onUnmounted } from 'vue'

export const useEventBus = () => {
  const events = ref({}) // 存儲事件訂閱

  // 訂閱事件
  const on = (eventName, callback) => {
    if (!events.value[eventName]) {
      events.value[eventName] = []
    }
    events.value[eventName].push(callback)
  }

  // 發(fā)布事件
  const emit = (eventName, ...args) => {
    if (events.value[eventName]) {
      events.value[eventName].forEach(callback => callback(...args))
    }
  }

  // 取消訂閱(避免內(nèi)存泄漏)
  const off = (eventName, callback) => {
    if (events.value[eventName]) {
      events.value[eventName] = events.value[eventName].filter(cb => cb !== callback)
    }
  }

  // 組件卸載時自動取消訂閱
  const useAutoOff = (eventName, callback) => {
    on(eventName, callback)
    onUnmounted(() => off(eventName, callback))
  }

  return { on, emit, off, useAutoOff }
}

// 2. 兄弟組件 A(發(fā)布事件)
<script setup>
import { useEventBus } from '@/utils/eventBus'
const { emit } = useEventBus()

const sendToBrother = () => {
  emit('brotherMsg', '來自兄弟A的消息')
}
</script>

// 3. 兄弟組件 B(訂閱事件)
<script setup>
import { useEventBus } from '@/utils/eventBus'
const { useAutoOff } = useEventBus()

// 自動取消訂閱,避免內(nèi)存泄漏
useAutoOff('brotherMsg', (msg) => {
  console.log('接收兄弟A消息:', msg)
})
</script>

2. 跨級組件通信:attrs/attrs /attrs/listeners(Vue2)/ useAttrs(Vue3)

核心:$attrs 包含了父作用域中未被 prop 所識別且獲取的特性綁定(class 和 style 除外),可通過 v-bind="$attrs" 傳入內(nèi)部組件;$listeners 包含了父作用域中的(不含 .native 修飾器的)v-on 事件監(jiān)聽器,可通過 v-on="$listeners" 傳入內(nèi)部組件,無需手動層層傳遞。

// Vue3 用法(useAttrs)
// 爺爺組件
<template>
  <Parent :name="userName" :age="22" @click="parentClick" @updateName="updateName" />
</template>

<script setup>
import { ref } from 'vue'
import Parent from './Parent.vue'

const userName = ref('張三')
const parentClick = () => console.log('爺爺組件點擊事件')
const updateName = (newName) => userName.value = newName
</script>

// 父組件(無需接收props,直接傳遞給子組件)
<template>
  <Child v-bind="attrs" v-on="listeners" />
</template>

<script setup>
import { useAttrs, useListeners } from 'vue'
const attrs = useAttrs() // 接收所有未被prop識別的屬性
const listeners = useListeners() // 接收所有父組件事件
</script>

// 子組件(直接接收爺爺組件傳遞的內(nèi)容)
<script setup>
const props = defineProps(['name', 'age'])
const emit = defineEmits(['click', 'updateName'])

// 觸發(fā)爺爺組件的事件
const triggerGrandpaEvent = () => {
  emit('click')
  emit('updateName', '李四')
}
</script>

3. 跨級組件通信:Provide / Inject(依賴注入)

核心:祖先組件中通過 provide 來提供變量,然后在子孫組件中通過 inject 來注入變量,跨級組件間建立了一種主動提供與依賴注入的關系,適合跨級共享簡單數(shù)據(jù)(如主題、用戶信息)。

// 祖先組件(頂層組件,如 App.vue)
<script setup>
import { provide, ref } from 'vue'

// 提供數(shù)據(jù)(可提供響應式數(shù)據(jù))
const theme = ref('light')
provide('theme', theme)

// 提供方法(修改共享數(shù)據(jù))
const changeTheme = () => {
  theme.value = theme.value === 'light' ? 'dark' : 'light'
}
provide('changeTheme', changeTheme)
</script>

// 子組件(任意層級,無需通過父組件傳遞)
<script setup>
import { inject } from 'vue'

// 接收共享數(shù)據(jù)和方法
const theme = inject('theme')
const changeTheme = inject('changeTheme')
</script>

<template>
  <div :class="theme">當前主題:{{ theme }}</div>
  <button @click="changeTheme">切換主題</button>
</template>

注意:Provide/Inject 是“單向向下”的通信,子組件不能直接修改注入的數(shù)據(jù),需通過祖先組件提供的方法修改,保證數(shù)據(jù)統(tǒng)一。

4. 跨級組件通信:$root

核心:通過 $root 可直接拿到根組件(App.vue)里的數(shù)據(jù)和方法,所有組件都能通過 $root 訪問根組件的內(nèi)容,適合簡單的全局共享場景(無需復雜狀態(tài)管理)。

// 根組件 App.vue
<script setup>
import { ref } from 'vue'

const globalMsg = ref('全局共享消息')
const globalMethod = () => {
  console.log('根組件全局方法被調(diào)用')
}

// 暴露給所有子組件
defineExpose({
  globalMsg,
  globalMethod
})
</script>

// 任意子組件(無論層級)
<script setup>
import { getCurrentInstance } from 'vue'

const instance = getCurrentInstance()
const accessRoot = () => {
  // 訪問根組件數(shù)據(jù)
  console.log(instance.root.globalMsg)
  // 調(diào)用根組件方法
  instance.root.globalMethod()
}
</script>

5. 全局狀態(tài)管理:Pinia / Vuex

核心:狀態(tài)管理器,集中式存儲管理所有組件的狀態(tài),任意組件(無論層級、關系)都可直接讀寫,適合大型項目、多組件共享數(shù)據(jù)(如用戶登錄狀態(tài)、購物車、全局配置)。Vue2 項目使用 Vuex,Vue3 優(yōu)先推薦 Pinia(比 Vuex 簡潔,無需 mutations)。

// 1. 安裝 Pinia 并創(chuàng)建倉庫(store/user.js)
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: null, // 全局共享的用戶信息
    token: ''
  }),
  actions: {
    // 修改狀態(tài)的方法
    setUserInfo(info) {
      this.userInfo = info
      this.token = info.token
    },
    logout() {
      this.userInfo = null
      this.token = ''
    }
  }
})

// 2. 任意組件使用(讀取/修改狀態(tài))
<script setup>
import { useUserStore } from '@/store/user'

const userStore = useUserStore()

// 讀取狀態(tài)
console.log(userStore.userInfo)

// 修改狀態(tài)(通過 actions,避免直接修改 state)
userStore.setUserInfo({ name: '張三', token: 'abc123' })

// 直接修改狀態(tài)(簡單場景,不推薦復雜項目)
userStore.token = 'def456'
</script>

// Vue2 Vuex 簡單示例
// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
export default new Vuex.Store({
  state: { userInfo: null },
  mutations: {
    setUserInfo(state, info) {
      state.userInfo = info
    }
  },
  actions: {
    setUserInfo({ commit }, info) {
      commit('setUserInfo', info)
    }
  }
})

// 組件中使用
this.$store.dispatch('setUserInfo', { name: '張三' })
console.log(this.$store.state.userInfo)

三、特殊場景:其他通信方式

針對特定場景(如頁面級組件通信),使用以下方式更高效,避免過度使用全局狀態(tài)。

路由傳參(組件無直接關系,通過路由跳轉通信)

核心:通過路由參數(shù)傳遞數(shù)據(jù),適合頁面級組件通信(如列表頁→詳情頁),分為「query 參數(shù)」和「params 參數(shù)」,無需組件間建立直接關聯(lián)。

// 1. 跳轉時傳遞參數(shù)(列表頁)
<script setup>
import { useRouter } from 'vue-router'

const router = useRouter()
const goToDetail = (id) => {
  // 方式1:query 參數(shù)(暴露在URL上,可刷新,適合簡單數(shù)據(jù))
  router.push({
    path: '/detail',
    query: { id, name: '張三' }
  })

  // 方式2:params 參數(shù)(不暴露在URL上,刷新丟失,適合敏感數(shù)據(jù))
  router.push({
    name: 'Detail', // 需配置路由name
    params: { id, name: '張三' }
  })
}
</script>

// 2. 詳情頁接收參數(shù)
<script setup>
import { useRoute } from 'vue-router'

const route = useRoute()
// 接收 query 參數(shù)
console.log(route.query.id)
// 接收 params 參數(shù)
console.log(route.params.id)
</script>

四、通信方式選型建議(實戰(zhàn)重點)

開發(fā)中無需死記所有方式,根據(jù)組件關系和項目規(guī)模選擇,避免過度復雜。以下為各通信方式適用場景對比表,可快速查閱選型:

通信方式適用組件關系適用項目規(guī)模核心優(yōu)勢注意事項
Props + emit父子組件所有規(guī)模原生支持、簡潔直接、單向數(shù)據(jù)流清晰,最常用子組件不能直接修改props,需通過emit通知父組件
v-model父子組件(表單/開關類)所有規(guī)模簡化雙向綁定代碼,語法簡潔,適配表單場景默認綁定modelValue,需配合update:modelValue事件
.sync 修飾符父子組件所有規(guī)模實現(xiàn)雙向綁定,比v-model更靈活,無需固定屬性名需觸發(fā)update:屬性名事件,才能同步修改父組件數(shù)據(jù)
ref / $refs父子組件所有規(guī)模父組件可直接操作子組件實例或DOM,靈活高效Vue3 setup需用defineExpose暴露屬性/方法
$children父子組件(父→多個直接子組件)所有規(guī)模可批量訪問所有直接子組件,適合批量操作不包含孫子組件,Vue3 setup需通過getCurrentInstance獲取
$parent父子組件(子→父)所有規(guī)模子組件可直接訪問父組件實例,無需emit傳遞Vue3 setup需通過getCurrentInstance獲取父組件
插槽(默認/具名)父子組件(內(nèi)容分發(fā))所有規(guī)模可傳遞模板/組件,適合組件封裝,靈活度高僅用于傳遞內(nèi)容,不適合傳遞復雜數(shù)據(jù)
插槽(作用域)父子組件(子傳父數(shù)據(jù))所有規(guī)模子傳數(shù)據(jù)、父定義渲染,兼顧靈活性和數(shù)據(jù)傳遞需通過插槽props接收子組件傳遞的數(shù)據(jù)
EventBus(事件總線)兄弟組件、跨級組件中小型項目實現(xiàn)簡單,無需層層傳遞,適配各類無直接關系組件需手動取消訂閱,避免內(nèi)存泄漏,大型項目易混亂
Provide / Inject跨級組件(祖先→子孫)所有規(guī)模(簡單共享)跨級傳遞無需中間組件轉發(fā),簡潔高效單向向下通信,子組件不能直接修改注入數(shù)據(jù)
$attrs / useAttrs跨級組件所有規(guī)模無需手動層層傳遞props和事件,減少冗余不適合傳遞大量復雜數(shù)據(jù),易造成數(shù)據(jù)混亂
$root任意組件(訪問根組件)中小型項目(簡單全局共享)直接訪問根組件數(shù)據(jù)/方法,實現(xiàn)簡單不適合復雜全局狀態(tài),大型項目易造成數(shù)據(jù)混亂
Pinia / Vuex任意組件(全局共享)大型項目統(tǒng)一管理全局狀態(tài),數(shù)據(jù)流轉可追溯,適配復雜場景小型項目使用會增加冗余,Vue3優(yōu)先Pinia
路由傳參頁面級組件(無直接關系)所有規(guī)模適合頁面跳轉時傳遞數(shù)據(jù),無需組件關聯(lián)params參數(shù)刷新丟失,query參數(shù)暴露在URL
  • 父子組件:優(yōu)先用 Props + emit,雙向綁定用 v-model.sync 修飾符,父操作子用 ref / refs∗∗,批量操作子用∗∗refs**,批量操作子用 **refs,批量操作子用children,子訪問父用 $parent,傳遞內(nèi)容用 插槽
  • 兄弟組件:中小型項目用 EventBus,大型項目用 Pinia;
  • 跨級組件:簡單共享用 Provide/Injectroot∗∗,需傳遞props/事件用∗∗root**,需傳遞props/事件用 **root,需傳遞props/事件用attrs / useAttrs,復雜共享用 Pinia;
  • 頁面級組件:用 路由傳參;
  • 全局復雜狀態(tài):大型項目用 Pinia / Vuex,小型項目用 $rootProvide/Inject。

總結:Vue 組件通信的核心是“數(shù)據(jù)流轉清晰”,優(yōu)先使用原生支持的方式,根據(jù)組件關系和項目規(guī)模選擇合適的方案,大型項目統(tǒng)一用 Pinia 管理全局狀態(tài),避免出現(xiàn)“通信混亂”的問題,提升代碼可維護性。

到此這篇關于Vue組件通信全場景詳解(新手也能看懂)的文章就介紹到這了,更多相關Vue組件通信內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

洛浦县| 和田市| 松溪县| 南部县| 珠海市| 江达县| 浪卡子县| 靖江市| 胶州市| 渝北区| 牡丹江市| 万荣县| 大庆市| 益阳市| 伊宁市| 秦安县| 文山县| 繁峙县| 潼南县| 洞口县| 景宁| 鄱阳县| 温泉县| 全椒县| 神农架林区| 云霄县| 景洪市| 青河县| 四川省| 安顺市| 城步| 兴业县| 射洪县| 台东市| 海宁市| 绥宁县| 乌兰察布市| 巨鹿县| 舞钢市| 嘉兴市| 南丰县|