vue $on是什么意思


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8" />

        <title>孙三峰--博客园</title>

        <script type="text/javascript" src="js/vue2.0.3.js" ></script>

        <script type="text/javascript">

            //准备一个空的实例对象

            var Event = new Vue();

            var A={

                template:`

                    <div style="border: 1px solid red; margin-bottom: 10px; width: 300px;">

                        <h4>A组件</h4>

                        <p>{{a}}</p>

                        <input type="button" value="把A数据给C" @click="send" />

                    </div>

                `,

                data(){

                    return {

                        a:'我是A里面的数据'

                    }

                },

                methods:{

                    send(){        //A发送数据

                        Event.$emit('a-msg',this.a);

                    }

                }

            };

            var B={

                template:`

                    <div style="border: 1px solid green; margin-bottom: 10px; width: 300px;">

                        <h4>B组件</h4>

                        <p>{{b}}</p>

                        <input type="button" value="把B数据给C" @click="send" />

                    </div>

                `,

                data(){

                    return {

                        b:'我是B里面的数据'

                    }

                },

                methods:{

                    send(){

                        Event.$emit('b-msg',this.b);

                    }

                }

            };

            var C={

                template:`

                    <div style="border: 1px dotted green; margin-bottom: 10px;width: 300px;">

                        <h4>我是C组件,我在坐等接收数据</h4>

                        <p>{{a}}</p>

                        <p>{{b}}</p>

                    </div>

                `,

                data(){

                    return{

                        a:'',

                        b:''

                    }

                },

                mounted(){        //两种接收的方式

                    var _this = this;

                    Event.$on('a-msg',function(a){

                        _this.a=a;

                    });

                    Event.$on('b-msg',function(b){

                        this.b = b;

                    }.bind(this))

                }

            };

            window.onload=function(){

                new Vue({

                    el:'#box',

                    data:{

 

                    },

                    components:{

                        'com-a':A,

                        'com-b':B,

                        'com-c':C

                    }

                })

            }

        </script>

    </head>

    <body>

        <div id="box">

            <com-a></com-a>

            <com-b></com-b>

            <com-c></com-c>

        </div>

    </body>

</html>

效果图:

086d02c303b0d63d9835603bae520b8.png

以上就是vue $on是什么意思的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

如何解决vue中layui报错问题

vue table 表格利用formatter属性格式化数据

vue文件怎么打开

layui是基于vue的吗?

vue-cli项目怎么使用vw单位?

什么是 vue

vue+axios+php如何实现上传文件功能?

怎么安装vue-cli

vue中computed和watch的区别是什么?

深入了解jquery和vue的区别(附代码)

更多相关阅读请进入《vue》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...