做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

vue中的event bus非父子組件通信解析

來源:懂視網 責編:小采 時間:2020-11-27 22:26:43
文檔

vue中的event bus非父子組件通信解析

vue中的event bus非父子組件通信解析:有時候非父子關系的組件也需要通信。在簡單的場景下,使用一個空的Vue實例作為中央事件總線: var bus = new Vue() // 觸發組件 A 中的事件 bus.$emit('id-selected', 1) // 在組件 B 創建的鉤子中監聽事件 bus.$on('id-selected',
推薦度:
導讀vue中的event bus非父子組件通信解析:有時候非父子關系的組件也需要通信。在簡單的場景下,使用一個空的Vue實例作為中央事件總線: var bus = new Vue() // 觸發組件 A 中的事件 bus.$emit('id-selected', 1) // 在組件 B 創建的鉤子中監聽事件 bus.$on('id-selected',

有時候非父子關系的組件也需要通信。在簡單的場景下,使用一個空的Vue實例作為中央事件總線:

var bus = new Vue()
// 觸發組件 A 中的事件
bus.$emit('id-selected', 1)
// 在組件 B 創建的鉤子中監聽事件
bus.$on('id-selected', function (id) {
 // ...
})

在更多復雜的情況下,你應該考慮使用專門的 狀態管理模式.就是用到了vuex

eventBus是作為兄弟關系的組件之間的通訊中介。

代碼示例:

<!DOCTYPE html>
<html>
<head>
<title>eventBus</title>
<script src="http://cdn.jsdelivr.net/vue/1.0.28/vue.min.js"></script>
</head>
<body>
<div id="todo-app">
<h1>todo app</h1>
<new-todo></new-todo>
<todo-list></todo-list>
</div>
<script>
var eventHub = new Vue( {
data(){
return{
todos:['A','B','C']
}
},
created:function () {
this.$on('add', this.addTodo)
this.$on('delete', this.deleteTodo)
},
beforeDestroy:function () {
this.$off('add', this.addTodo)
this.$off('delete', this.deleteTodo)
},
methods: {
addTodo: function (newTodo) {
this.todos.push(newTodo)
},
deleteTodo: function (i) {
this.todos.splice(i,1)
}
}
})
var newTodo = {
template:`<div><input type="text" autofocus v-model="newtodo"/><button @click="add">add</button></div>`,
data(){
return{
newtodo:''
}
},
methods:{
add:function(){
eventHub.$emit('add', this.newtodo)
this.newtodo = ''
}
}
}
var todoList = {
template:`<ul><li v-for="(index,item) in items">{{item}} \
 <button @click="rm(index)">X</button></li> \
 </ul>`,
 data(){
 return{
 items:eventHub.todos
 }
 },
 methods:{
 rm:function(i){
 eventHub.$emit('delete',i)
 }
 }
}
var app= new Vue({
el:'#todo-app',
components:{
newTodo:newTodo,
todoList:todoList
}
})
</script>
</body>
</html>

效果圖如下:

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

vue中的event bus非父子組件通信解析

vue中的event bus非父子組件通信解析:有時候非父子關系的組件也需要通信。在簡單的場景下,使用一個空的Vue實例作為中央事件總線: var bus = new Vue() // 觸發組件 A 中的事件 bus.$emit('id-selected', 1) // 在組件 B 創建的鉤子中監聽事件 bus.$on('id-selected',
推薦度:
標簽: VUE event 通信
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 仁寿县| 册亨县| 渑池县| 永修县| 鄂托克旗| 五华县| 鄂伦春自治旗| 抚顺县| 正阳县| 雷山县| 彩票| 固镇县| 达州市| 银川市| 南召县| 六安市| 许昌市| 临沂市| 建宁县| 林甸县| 杭锦后旗| 城步| 新巴尔虎右旗| 延吉市| 金门县| 泽普县| 哈巴河县| 房产| 吴川市| 唐河县| 安新县| 西盟| 舟曲县| 文登市| 交口县| 星座| 新化县| 伊金霍洛旗| 新绛县| 荔浦县| 江阴市|