vue vue-router vuex element-ui axios的学习笔记(十四)商品详情页

思路

1、写api

Image 152.png

2、写详情页组件和路由

router---->index.js

Image 153.png

productcontent.vue

Image 154.png

3、在productlist.vue把路由加上

Image 155.png

4、mock.js

Image 156.png

5、详情页添加内容

<template>
  <div>
    <h1>productcontent.vue</h1>
    <p>{{$route.params.class}}</p>
    <p>{{$route.params.productname}}</p>
    <div>
      <h2 v-text="product.productname"></h2>
      <p>价格:{{product.productprice}}元</p>
      <p>销量:{{product.productsells}}</p>
      <img :src="product.productimage">
      <p>{{product.productintro}}</p>
    </div>
  </div>
</template>
<script>
import {GetProduct} from '../../../api/api'
export default {
  data () {
    return {
      product: {}
    }
  },
  mounted () {
    let params = {
      productname: this.$route.params.productname,
      productclass: this.$route.params.class
    }
    GetProduct(params).then(res => {
      console.log(res)
      this.product = res.data.curproduct
    })
  }
}
</script>


效果

GIF5.gif

总结:商品页面的功能基本完成了,接下来就是把样式写好

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 《你就是你》 你就是你 那个别具一格独一无二的你 你就是你 那个出类拔萃与众不同的你 你就是你 那个勇往直前不忍气...
    向昕阅读 1,378评论 0 1
  • 部署开始。 奥提莉亚、灾厄带着奴隶们来到屏障边缘准备逃离。 月华奎灵和薇薇·莱米待在了之前的那个屋子里,月华奎灵带...
    月华奎灵阅读 3,596评论 0 1
  • 叔叔参军的时候,我还小,只依稀记得他穿上崭新的军装,戴着大红花,在锣鼓声中踏上军旅。 到了部队后的几年里,他没有享...
    虬田阅读 6,718评论 143 146

友情链接更多精彩内容