1. //Tips:在vue中,子组件不要直接修改从父组件传递过来的数据
    2. <template>
    3. <div @click="handleAdd">{{data}}</div>
    4. </template>
    5. <script>
    6. export default {
    7. props:{
    8. data:{
    9. type:Number,
    10. required:true
    11. }
    12. },
    13. methods:{
    14. handleAdd(){
    15. this.$emit("add")
    16. }
    17. }
    18. };
    19. <template>
    20. <div class="home">
    21. <h4>{{count}}</h4>
    22. <count :data="count" @add="handleAdd"/>
    23. <Test :data.sync="count"/>
    24. </div>
    25. </template>
    26. <script>
    27. import Count from '@/components/Count.vue'
    28. export default {
    29. name: 'home',
    30. data(){
    31. return {
    32. count:10
    33. }
    34. },
    35. components:{
    36. Count
    37. },
    38. methods:{
    39. handleAdd(){
    40. this.count++;
    41. }
    42. }
    43. }
    44. </script>