PageTwo.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <div>
  3. <h1>页面二</h1>
  4. <!-- 使用组件仅需 以组件名称为标签名即可 -->
  5. <h1> 当前组件内的数字为:{{ msg }}</h1>
  6. <!-- 可以为组件自定义事件名称 -->
  7. <AddControl v-bind:title="title" v-on:changeCount="childChange" ></AddControl>
  8. <AddControl title="累加器2"></AddControl>
  9. </div>
  10. </template>
  11. <script>
  12. // 引入组件 import from
  13. // import 后边为引入的组件名称 from 后边为组件的地址
  14. // vue 中 @ 表示 src 目录
  15. import AddControl from '@/components/AddControl.vue'
  16. export default {
  17. name: 'PageTwo',
  18. data(){
  19. return {
  20. title:'累加器11',
  21. msg:""
  22. }
  23. },
  24. methods:{
  25. childChange(count){
  26. console.log(count);
  27. this.msg = count;
  28. }
  29. },
  30. // components (注册组件)
  31. components: {
  32. // 组件的名称
  33. AddControl
  34. }
  35. }
  36. </script>