0
点赞
收藏
分享

微信扫一扫

手写springboot启动器, 学习SpringBoot的最佳实践

西街小学的王 03-23 22:30 阅读 2

一、情景说明

Vue3的用法略有区别

Vue2的用法:https://blog.csdn.net/Brave_heart4pzj/article/details/136326608

二、案例

简单理解:RouterLinkto怎么写,router.replacerouter.push中就怎么配置。

<!-- 跳转的按钮 -->
<button @click="showNewsDetail(news)">查看新闻</button>

<script setup lang="ts" name="News">
  import {reactive} from 'vue'
  import {RouterView,RouterLink,useRouter} from 'vue-router'

  const newsList = reactive([
    {id:'asfdtrfay01',title:'很好的抗癌食物',content:'西蓝花'},
    {id:'asfdtrfay02',title:'如何一夜暴富',content:'学IT'},
    {id:'asfdtrfay03',title:'震惊,万万没想到',content:'明天是周一'},
    {id:'asfdtrfay04',title:'好消息!好消息!',content:'快过年了'}
  ])

  const router = useRouter()

  interface NewsInter {
    id:string,
    title:string,
    content:string
  }
  //replace方式跳转
  function showNewsDetail(news:NewsInter){
    router.replace({
      name:'xiang',
      query:{
        id:news.id,
        title:news.title,
        content:news.content
      }
    })
  }
  
  //push方式跳转
  function showNewsDetail(news:NewsInter){
    router.push({
      name:'xiang',
      query:{
        id:news.id,
        title:news.title,
        content:news.content
      }
    })
  }
</script>
举报

相关推荐

0 条评论