Demo4.vue 745 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <div class="demo4">
  3. <p>你好 我有一个帽衫</p>
  4. </div>
  5. </template>
  6. <script>
  7. import pubsub from 'pubsub-js';
  8. export default {
  9. data() {
  10. return {
  11. pubId:null
  12. }
  13. },
  14. mounted() {
  15. // this.$reds.xxx.$on
  16. // this.$on
  17. this.pubId = pubsub.subscribe("part1",this.namesChange)
  18. // this.$bus.$on("part1",this.namesChange)
  19. },
  20. methods:{
  21. namesChange(xxx,demo){
  22. // console.log(xxx,'xxx')
  23. alert("牛"+demo)
  24. }
  25. },
  26. beforeDestroy() {
  27. // this.$bus.$off();
  28. pubsub.unsubscribe(this.pubId);
  29. }
  30. }
  31. </script>
  32. <style scoped>
  33. .demo4 {
  34. width: 300px;
  35. height: 300px;
  36. border:3px solid #0f0;
  37. }
  38. </style>