提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

3 weeks ago
  1. <template>
  2. <div class="news">
  3. <!--导航区-->
  4. <ul>
  5. <li v-for="news in newsList" :key="news.id">
  6. <!--第一种写法-->
  7. <!-- <RouterLink :to="`/news/detail?id=${news.id}
  8. &title=${news.title}
  9. &content=${news.content}`">{{news.title}}</RouterLink> -->
  10. <!-- 第二种写法 -->
  11. <RouterLink
  12. :to="{
  13. path: '/news/detail',
  14. query: {
  15. id: news.id,
  16. title: news.title,
  17. content: news.content}}">
  18. {{news.title}}
  19. </RouterLink>
  20. </li>
  21. </ul>
  22. <!--内容区-->
  23. <div class="news-content">
  24. <RouterView></RouterView>
  25. </div>
  26. </div>
  27. </template>
  28. <script lang="ts" setup name="News">
  29. import { reactive } from 'vue';
  30. import { RouterLink, RouterView } from 'vue-router';
  31. const newsList = reactive([
  32. {id: 1, title: '新闻1',content: '新闻1的内容'},
  33. {id: 2, title: '新闻2',content: '新闻2的内容'},
  34. {id: 3, title: '新闻3',content: '新闻3的内容'},
  35. {id: 4, title: '新闻4',content: '新闻4的内容'},
  36. ])
  37. </script>
  38. <style scoped>
  39. .news {
  40. padding: 0 20px;
  41. display: flex;
  42. justify-content: space-between;
  43. align-items: center;
  44. height: 100px;
  45. }
  46. .news ul {
  47. margin-top: 30px;
  48. /* list-style: none; */
  49. padding-left: 10px;
  50. }
  51. .news li>a{
  52. text-decoration: none;
  53. color: #000;
  54. }
  55. </style>