index.vue 514 B

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <ul>
  3. <li v-for="menu in menus">
  4. <h2 @click="go(menu.name)">{{menu.title}}</h2>
  5. </li>
  6. </ul>
  7. </template>
  8. <script>
  9. export default {
  10. props: ['menus'],
  11. data () {
  12. return {
  13. currentName: '',
  14. }
  15. },
  16. watch: {
  17. '$route' () {
  18. this.checkRoute()
  19. },
  20. },
  21. methods: {
  22. go (name) {
  23. this.$router.push({ path: `/${name}/` })
  24. },
  25. checkRoute () {
  26. this.currentName = this.$route.name
  27. },
  28. },
  29. mounted () {
  30. this.checkRoute()
  31. },
  32. }
  33. </script>