vue中跳轉頁面邏輯


跳轉詳情頁面具體代碼

寫這個頁面需要安裝兩個

1.安裝axios命令

Cnpm install axios --save

2.安裝vant

Cnpm install vant --save

 

index.Js里面配置要跳轉頁面的路由

 

 

 

 

 

main.js里面用vue引入剛安裝上的兩個插件

 

 

 

這個是home.vue里的內容

 <template>

  <div>

//下面那個正在加載時給它個判斷

    <div v-if="isShow">正在加載......</div>

 

    <div class="div1"> 

    <div v-for="(item,index) in goods" :key="index"

    @click="gotoDetails(item.id)">

      <img :src="item.mainPic" width="150px" />

      <p>{{item.title}}</p>

      <p>

        <span style="color:red">{{item.actualPrice}}</span>

        <s style="font-size:12px">{{item.originalPrice}}</s>

      </p>

      <p>銷售:{{item.monthSales}}</p>

    </div>

 

    <div v-for="(item,index) in goods" :key="index"

    @click="gotoDetails(item.id)">

      <img :src="item.mainPic" width="150px" />

      <p>{{item.title}}</p>

      <p>

        <span style="color:red">{{item.actualPrice}}</span>

        <s style="font-size:12px">{{item.originalPrice}}</s>

      </p>

      <p>銷售:{{item.monthSales}}</p>

    </div>

</div>

 

  </div>

</template>

 

 <script>

export default {

  data() {

    return {

      goods: [],

      isShow: true

    };

  },

  mounted() {

this.$axios

//下面那個是在官網中引入的Apl接口

      .get(" http://api.kudesoft.cn/tdk/goods", {

        params: {

          pageId: 2,

          cids: 6

        }

      })

      .then(res => {

        let goods = res.data.data.data.list;

        this.goods = goods;

        this.isShow = false;

      })

      .catch(err => {

        console.log(err);

      });

  },

  methods: {

    gotoDetails(id) {

      this.$router.push({

        path: "/details",

        query: {

          id

        }

      });

    }

  }

};

</script>

 

 <style>

 .div1{

   width: 100%;

   display: flex;

   justify-content: space-between;

 }

</style>

 

 

這個是在跳轉頁面是要創建的跳轉到的頁面 details.vue

<template>

  <div>

    <button @click="back">返回</button>

    <van-swipe :autoplay="3000" indicator-color="white" style="width:200px">

      <van-swipe-item v-for="(img,index) in goodItem.imgs" :key="index">

        <img :src="img" alt width="200px" />

      </van-swipe-item>

    </van-swipe>

    <div>{{goodItem.title}}</div>

    <div>

      <a :href="goodItem.couponLink">領劵</a>

    </div>

    <h1>商品詳情:</h1>

    <div>

      <img v-for="(url,index) in goodItem.detailPics" :key="index" :src="url" width="600px" />

    </div>

  </div>

</template>

 

<script>

export default {

  data() {

    return {

      goodItem: {}

    };

  },

  mounted() {

    let id = this.$route.query.id;

    this.$axios

      .get("http://api.kudesoft.cn/tdk/details", {

        params: {

          id

        }

      })

      .then(res => {

        this.goodItem = res.data.data.data;

        this.goodItem.imgs = this.goodItem.imgs.split(",");

        this.goodItem.detailPics = this.goodItem.detailPics.split(",");

      })

      .catch(err => {

        console.log(err);

      });

  },

  methods: {

    back() {

      window.history.back();

    }

  }

};

</script>

 

<style>

</style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM