1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Document</title>
    8. <script src="./lib/vue.js"></script>
    9. </head>
    10. <body>
    11. <template id="tmpcom">
    12. <div>
    13. <hr>
    14. <input type="button" value="+1" @click="increment">
    15. <h3>{{msg}}</h3>
    16. <hr>
    17. </div>
    18. </template>
    19. <div id="app">
    20. <com></com>
    21. <com></com>
    22. <com></com>
    23. </div>
    24. <script>
    25. Vue.component('com',{
    26. template:"#tmpcom",
    27. methods:{
    28. increment(){
    29. this.msg+=1
    30. }
    31. },
    32. data:function(){
    33. return {
    34. msg:0
    35. }
    36. }
    37. })
    38. var vm=new Vue({
    39. el:'#app',
    40. data:{},
    41. methods:{}
    42. });
    43. </script>
    44. </body>
    45. </html>

    1.gif