PageTwo.vue 730 B

1234567891011121314151617181920212223242526272829303132
  1. <template>
  2. <div class="container">
  3. <h1>我是页面二</h1>
  4. <h1>{{num}}</h1>
  5. <button @click="addNum">增加</button>
  6. </div>
  7. </template>
  8. <script>
  9. // export default 导出当前组件的实例对象 必须写 否则路文件中由找不到当前组件
  10. export default {
  11. // 组件的名称
  12. name:"PageTwo",
  13. // 组件的状态数据 必须是一个函数 返回一个对象
  14. data(){
  15. return{
  16. num:10
  17. }
  18. },
  19. // 组件的方法
  20. methods:{
  21. addNum(){
  22. this.num++;
  23. }
  24. }
  25. }
  26. </script>
  27. <!-- scoped 表示当前样式只作用于当前组件 设置样式的作用域 -->
  28. <style scoped>
  29. .container{
  30. display: block;
  31. }
  32. </style>