reciver.vue 769 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <view>
  3. <view class="reciver">
  4. {{msg===''?'等待发送':'收到消息:'}}{{msg}}
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. import bus from './bus.js'
  10. export default {
  11. data() {
  12. return {
  13. msg: ''
  14. }
  15. },
  16. created() {
  17. uni.$on('cc', this.recive)
  18. bus.$on('cc', this.recive)
  19. },
  20. beforeDestroy() {
  21. uni.$off('cc',this.recive)
  22. bus.$off('cc', this.recive)
  23. },
  24. methods: {
  25. recive(e) {
  26. this.msg = e.msg
  27. }
  28. }
  29. }
  30. </script>
  31. <style>
  32. .reciver {
  33. padding: 40px 0px;
  34. text-align: center;
  35. line-height: 40px;
  36. }
  37. </style>