随笔- 310  文章- 1  评论- 0  阅读- 86066 
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
<!DOCTYPE html>
<html>
<head>
    <title>Vue Demo</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <div id="firstVue">
     <p>{{msg}}</p>
    <button-demo></button-demo
    <child v-bind:message="msg"></child>
    <button-counter></button-counter>   
    </div>
     
      
</body>
<script type="text/javascript">
 
   Vue.component('button-demo',{
        template:'<button>Hello button-demo!</button>'
    });
    //注册了'button-demo'以后,<button-demo></button-demo>就等价于<button>Hello here!</button>
     
    // 组件 child
     Vue.component('child', {
      // 声明 props
      props: ['message'],
      template: '<div><span>{{ message }}</span></div>'
    });
 
    //定义button-counter组件
    Vue.component('button-counter',{
        //定义数据
        data:function(){
            return {
                count: 0
            }
        },
        //定义方法
        methods:{
            clickAdd: function(){
                this.count++
            }
        },
        template :'<button @click="clickAdd">You clicked me {{count}} times</button>'
 
    });
 
    var myVue = new Vue({
        el: "#firstVue",
        data:{
         msg:"hello world"
        }
         
    })
</script>
 
</html>

  

 posted on   boye169  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
历史上的今天:
2021-07-10 python web模板 jinja2
点击右上角即可分享
微信分享提示