欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2019年07月10日 08:35:52   作者:des雷鋒  
這篇文章主要介紹了Vue編程式跳轉(zhuǎn)的實例代碼,文中給大家介紹了vue 編程式j(luò)s跳轉(zhuǎn)路由,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

編程式跳轉(zhuǎn)的實現(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', // 詳情需要配一個id,獲取遍歷
   name: 'detail',
   component: () => import('./views/detail/index.vue')
  },

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

請看goNews()方法

<template>
  <!-- 所有的內(nèi)容要被根節(jié)點包含起來 -->
  <div id="home">  
    我是首頁組件
    <button @click="goNews()">通過js跳轉(zhuǎn)到新聞頁面</button>
  </div>
</template>
<script>
  export default{
    data(){
      return {        
        msg:'我是一個home組件'
      }
    },
    methods:{
      goNews(){
        // 注意:官方文檔寫錯了
        //第一種跳轉(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)的實例代碼 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論