初始化(包含登录模块)
This commit is contained in:
3
pages/template/component-communication/bus.js
Normal file
3
pages/template/component-communication/bus.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
export default new Vue()
|
||||
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<view>
|
||||
<page-head title="组件通讯示例"></page-head>
|
||||
<view class="uni-padding-wrap">
|
||||
<view class="uni-btn-v">
|
||||
<reciver></reciver>
|
||||
<sender></sender>
|
||||
<sender-bus></sender-bus>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import reciver from './reciver.vue'
|
||||
import sender from './sender.vue'
|
||||
import senderBus from './sender-bus.vue'
|
||||
export default {
|
||||
components:{
|
||||
reciver,
|
||||
sender,
|
||||
senderBus
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
36
pages/template/component-communication/reciver.vue
Normal file
36
pages/template/component-communication/reciver.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="reciver">
|
||||
{{msg===''?'等待发送':'收到消息:'}}{{msg}}
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
msg: ''
|
||||
}
|
||||
},
|
||||
created() {
|
||||
uni.$on('cc', this.recive)
|
||||
},
|
||||
beforeDestroy() {
|
||||
uni.$off('cc',this.recive)
|
||||
},
|
||||
methods: {
|
||||
recive(e) {
|
||||
this.msg = e.msg
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.reciver {
|
||||
padding: 40px 0px;
|
||||
text-align: center;
|
||||
line-height: 40px;
|
||||
}
|
||||
</style>
|
||||
24
pages/template/component-communication/sender-bus.vue
Normal file
24
pages/template/component-communication/sender-bus.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<view class="sender-container">
|
||||
<button type="primary" @click="send">自定义EventBus</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
send() {
|
||||
let num = parseInt(Math.random() * 10000)
|
||||
uni.$emit('cc', {
|
||||
msg: 'From event bus -> ' + num
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sender-container{
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
24
pages/template/component-communication/sender.vue
Normal file
24
pages/template/component-communication/sender.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<view class="sender-container">
|
||||
<button type="primary" @click="send">点击发送消息</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
send() {
|
||||
let num = parseInt(Math.random() * 10000)
|
||||
uni.$emit('cc', {
|
||||
msg: 'From uni.$emit -> ' + num
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sender-container{
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user