国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

Vue編程式跳轉(zhuǎn)的實(shí)例代碼詳解

2024-05-06 15:37:05
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

編程式跳轉(zhuǎn)的實(shí)現(xiàn)代碼,如下所示:

<template> <ul class = "prolist">  <!-- //產(chǎn)品 -->  <!-- :to = "/detail/item.id" -->  <!-- 聲明式跳轉(zhuǎn) :to = "{ name: 'detail',params: { id: item.id } }" -->  <!-- <router-link :to = "{ name: 'detail',params: { id: item.id } }" tag = "li" class = "proitem" v-for="(item,index) of iss" :key='index'>   <div class = "itemimg">    <img :src="item.images.small" :alt="item.alt">   </div>   <div class = "iteminfo">    <h3>{{ item.title }}</h3>    <div class = "directors">     <span v-for="(itm,idx) of item.directors" :key="idx">      {{ itm.name }}/     </span>    </div>    <Rating :rating='(item.rating.average / 2).toFixed(1)' />   </div>  </router-link> -->  <!-- 編程式跳轉(zhuǎn) -->  <!-- @click="godetail(item.id) -->  <li class = "proitem" v-for="(item,index) of iss" @click="goDetail(item.id)" :key='index'>   <div class = "itemimg">    <img :src="item.images.small" :alt="item.alt">   </div>   <div class = "iteminfo">    <h3>{{ item.title }}</h3>    <div class = "directors">     導(dǎo)演:<span v-for="(itm,idx) of item.directors" :key="idx">      {{ itm.name }}/     </span>    </div>    <div class = "casts">      演員:<span v-for="(itm,idx) of item.casts" :key="idx">      {{ itm.name }}/     </span>    </div>    <Rating :rating="(item.rating.average / 2).toFixed(1)"/>   </div>  </li> </ul></template><script>import Rating from '@/components/common/Rating'export default { methods: {  goDetail (id) {   // console.log(this.$router)   // this.$router.push('/detail/' + id) //id由函數(shù)獲得   // this.$router.push({ name: 'detail', params: { id: id } }) // 另一種方法   this.$router.push({ path: '/detail/' + id }) // 另一種方法  } }, props: ['iss'], components: {  Rating }}</script>router.js:{   // path: '/detail',   path: '/detail/:id', // 詳情需要配一個(gè)id,獲取遍歷   name: 'detail',   component: () => import('./views/detail/index.vue')  },

ps:下面看下vue 編程式j(luò)s跳轉(zhuǎn)路由

請(qǐng)看goNews()方法

<template>  <!-- 所有的內(nèi)容要被根節(jié)點(diǎn)包含起來(lái) -->  <div id="home">      我是首頁(yè)組件    <button @click="goNews()">通過(guò)js跳轉(zhuǎn)到新聞頁(yè)面</button>  </div></template><script>  export default{    data(){      return {                msg:'我是一個(gè)home組件'      }    },    methods:{      goNews(){        // 注意:官方文檔寫錯(cuò)了        //第一種跳轉(zhuǎn)方式        // this.$router.push({ path: 'news' })        // this.$router.push({ path: '/content/495' });        //另一種跳轉(zhuǎn)方式          //  { path: '/news', component: News,name:'news' },          // router.push({ name: 'news', params: { userId: 123 }})          this.$router.push({ name: 'news'})      }    }  }</script><style lang="scss" scoped></style>            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 乐亭县| 当涂县| 彭州市| 伊金霍洛旗| 扎赉特旗| 永康市| 临颍县| 河津市| 灵川县| 武安市| 沧州市| 达尔| 东山县| 阿城市| 来安县| 武夷山市| 柳州市| 翁源县| 西峡县| 莲花县| 隆子县| 灵山县| 姚安县| 交城县| 司法| 泸水县| 浙江省| 锡林郭勒盟| 蚌埠市| 山丹县| 乌拉特中旗| 元氏县| 容城县| 肇东市| 祁东县| 通道| 禹城市| 长治县| 潞西市| 库尔勒市| 贵溪市|