Vue編程式跳轉(zhuǎn)的實(shí)例代碼詳解
編程式跳轉(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>
總結(jié)
以上所述是小編給大家介紹的Vue編程式跳轉(zhuǎn)的實(shí)例代碼 ,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- vue-router實(shí)現(xiàn)編程式導(dǎo)航的代碼實(shí)例
- vue-router命名路由和編程式路由傳參講解
- 講解vue-router之什么是編程式路由
- vue 列表頁(yè)跳轉(zhuǎn)詳情頁(yè)獲取id以及詳情頁(yè)通過(guò)id獲取數(shù)據(jù)
- vue單頁(yè)面實(shí)現(xiàn)當(dāng)前頁(yè)面刷新或跳轉(zhuǎn)時(shí)提示保存
- Vue頁(yè)面跳轉(zhuǎn)動(dòng)畫效果的實(shí)現(xiàn)方法
- vue單頁(yè)面應(yīng)用打開新窗口顯示跳轉(zhuǎn)頁(yè)面的實(shí)例
- vue項(xiàng)目中跳轉(zhuǎn)到外部鏈接的實(shí)例講解
- 解決vue單頁(yè)路由跳轉(zhuǎn)后scrollTop的問(wèn)題
- vue 實(shí)現(xiàn)在函數(shù)中觸發(fā)路由跳轉(zhuǎn)的示例
相關(guān)文章
前端語(yǔ)法高亮插件Prism.js使用詳細(xì)教程
最近項(xiàng)目有代碼高亮的需求,這邊是選用Prism.js來(lái)進(jìn)行代碼高亮,Prism是一款輕量級(jí)、可擴(kuò)展的語(yǔ)法高亮器,根據(jù)現(xiàn)代?Web?標(biāo)準(zhǔn)構(gòu)建,應(yīng)用廣泛,這篇文章主要給大家介紹了關(guān)于前端語(yǔ)法高亮插件Prism.js使用詳細(xì)教程的相關(guān)資料,需要的朋友可以參考下2024-05-05JS中簡(jiǎn)單的實(shí)現(xiàn)像C#中using功能(有源碼下載)
JS中簡(jiǎn)單的實(shí)現(xiàn)像C#中using功能(有源碼下載)...2007-01-01JavaScript中call、apply、bind實(shí)現(xiàn)原理詳解
其實(shí)在很多文章都會(huì)寫call,apply,bind,但個(gè)人覺(jué)著如果不弄懂原理,是很難理解透的,所以這篇文章主要介紹了JavaScript中call、apply、bind實(shí)現(xiàn)原理的相關(guān)資料,需要的朋友可以參考下2021-06-06js實(shí)現(xiàn)感應(yīng)鼠標(biāo)圖片透明度變化的方法
這篇文章主要介紹了js實(shí)現(xiàn)感應(yīng)鼠標(biāo)圖片透明度變化的方法,涉及javascript鼠標(biāo)操作及css修改技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02JS實(shí)現(xiàn)的判斷方法、變量是否存在功能示例
這篇文章主要介紹了JS實(shí)現(xiàn)的判斷方法、變量是否存在功能,涉及javascript針對(duì)變量、方法判斷與異常處理操作技巧,需要的朋友可以參考下2018-05-05Javascript對(duì)象中關(guān)于setTimeout和setInterval的this介紹
Javascript對(duì)象中關(guān)于setTimeout和setInterval的this介紹,需要的朋友可以參考下2012-07-07js動(dòng)態(tài)修改整個(gè)頁(yè)面樣式達(dá)到換膚效果
這篇文章主要介紹了通過(guò)js動(dòng)態(tài)修改整個(gè)頁(yè)面樣式達(dá)到換膚效果,需要的朋友可以參考下2014-05-05ionic由于使用了header和subheader導(dǎo)致被遮擋的問(wèn)題的兩種解決方法
這篇文章主要介紹了ionic由于使用了header和subheader導(dǎo)致被遮擋的問(wèn)題的兩種解決方法,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09