vue vue-router vuex element-ui axios的学习笔记(十五)商品页面写一下样式

product.vue

<template>
<div class="container">
  <el-row>
    <el-col class="menu-box" :span="6">
      <p></p>
      <el-menu
        class="menu"
        :default-active="$route.path"
        router
        background-color="#fff"
        text-color="#267943"
        active-text-color="#000">
        <el-menu-item v-for="(item, index) in productclass" 
          :index="'/product/'+item.class"
          :key="'/product/'+item.class"
          v-text="item.name">
        </el-menu-item>
      </el-menu>
    </el-col>
    <!-- 右边主要内容 -->
    <el-col :span="18">
      <!-- 搜索框 -->
      <el-input 
      type="text"
      class="el-input"
      placeholder="请输入商品名"
      v-model="searchName">
      <i slot="prefix" class="el-input__icon el-icon-search"></i>
      </el-input>
      <el-button 
        type="primary"
        :disabled="disabled"
        @click="search"
        :loading="loading">
        搜索
      </el-button>
      <!-- 商品列表渲染的地方 -->
      <transition name="el-zoom-in-center">
        <router-view :key="key"></router-view>
      </transition>
    </el-col>
  </el-row>
</div>

</template>
<script>
import {SearchProductList} from '../../api/api'
export default {
  data () {
    return {
      searchName: '',
      isactive: false,
      loading: false,
      productclass: [
        {
          class: 'all',
          name: '全部商品'
        },
        {
          class: 'pomegranate',
          name: '石榴'
        },
        {
          class: 'pine',
          name: '松子'
        },
        {
          class: 'ham',
          name: '火腿'
        },
        {
          class: 'other',
          name: '其它商品'
        }
      ]
    }
  },
  computed: {
    key () {
      return this.$route.params.class + new Date()
    },
    disabled () {
      if (this.searchName === '') {
        return true
      } else {
        return false
      }
    }
  },
  methods: {
    search () {
      this.loading = true
      let searchparams = this.searchName
      SearchProductList(searchparams).then(res => {
        this.loading = false
        if (res.data.code === 200) {
          this.$router.push({
            path: '/product/search',
            query: {name: this.searchName}
          })
        } else {
          this.$notify({
            title: '很抱歉',
            message: res.data.msg,
            type: 'warning',
            offset: 200
          })
          this.$router.push('/product/all')
        }
      })
    }
  }
}
</script>
<style scoped>
.el-input {
  margin: 20px 0;
  width: 70%;
}
.el-button {
  width: 25%;
  margin-right: 5px; 
}
.menu {
  position: fixed;
  width: 200px;
  top: 150px;
  left: 50px;
  box-shadow: 0 0 6px #ccc;
}
.is-active {
  background: #669966 !important;
  /* border-bottom: 3px solid #66CC00 !important; */
  color: #fff !important;
  font-weight: bold !important;
}
@media screen and (max-width: 767px) {
  .menu {
    position: fixed;
    width: 25%;
    top: 100px;
    left: 5px;
    box-shadow: 0 0 6px #ccc;
  }
  .is-active {
    background: #669966 !important;
    /* border-bottom: 3px solid #66CC00 !important; */
    color: #fff !important;
    font-weight: bold !important;
  }
}
</style>

productlist.vue

<template>
  <div>
    <div class="title">
      <h1 v-text="$route.params.class"></h1>
    </div>
    <!-- <p>共{{productlist.length}}个商品</p> -->
    <ul>
      <template v-for="(item, index) in productlist">
        <el-row  class="item" :key="item.productclass">
          <router-link 
            :to="'/product/'+item.productclass+'/'+item.productname"
            :key="item.productclass">
            <el-col :span="8">
              <img :src="item.productimage" >
            </el-col>
          </router-link>  
          <el-col :span="16">
            <h3>{{item.productname}}</h3>
            <p class="intro">{{item.productintro}}</p>
            <router-link 
              :to="'/product/'+item.productclass+'/'+item.productname"
              :key="item.productclass">
              <p class="link">了解详情...</p>
            </router-link>
            <p class="sellnum">累计发货<span>{{item.productsells}}</span>件</p>
            <p class="price">全国包邮价<span>{{item.productprice}}</span>元</p>
            <!-- <el-input-number size="mini" v-model="addnum"></el-input-number> -->
          </el-col>
        </el-row>
      </template>
    </ul>
  </div>
</template>
<script>
import {GetProductList, SearchProductList} from '../../../api/api'
export default {
  data () {
    return {
      productlist: [],
      addnum: 0
    }
  },
  // methods: {
  //   formatClass () {
  //     if (this.$route.params.class === 'all' || 'ham' || 'ham' || 'ham') {

  //     }
  //   }
  // },
  mounted () {
    if (this.$route.query.name) {
      // 获取查询列表
      // console.log(this.$route.query.name)
      let searchparams = this.$route.query.name
      SearchProductList(searchparams).then(res => {
        // console.log(res)
        if (res.data.code === 200) {
          this.productlist = res.data.searchRes
        } else {
          this.$notify({
            title: '很抱歉',
            message: res.data.msg,
            type: 'warning',
            offset: 200
          })
          this.$router.push('/product/all')
        }
      })
    } else {
      // 获取分类列表
      let params = null
      if (this.$route.params.class === 'all') {
        params = ''
      } else {
        params = this.$route.params.class
      }
      GetProductList(params).then(res => {
        // console.log(res)
        this.productlist = res.data.productlist
      })
    }
  }
}
</script>
<style scoped>
a {
  text-decoration: none;
  color: #999;
}
a:hover {
  color: #669966;
}
.title {
  height: 60px;
  border-left: 4px solid #669966; 
  margin: 0 15px;
  background-color: #f2f3f2;
  text-align: left;
  padding-left:20px; 
  line-height: 60px;
}
ul {
  padding: 0;
  margin: 0 15px;
}
.item {
  margin: 25px 0;
  /* background: #f2f3f2; */
  box-shadow: 0 0 30px #ccc;
  border-radius: 15px; 
}
.item:hover {
  /* border: 1px solid silver;  */
  background: #eee;
}
img {
  width: 100%;
  max-width: 500px;
  padding: 10px;
  border-radius: 15px; 
}
.intro,.price,.sellnum {
  margin: 0 15px 0 25px;
  text-align: left;
  color: #666;
  line-height: 2;
  letter-spacing: 1.2;
}
.link {
  text-align: right;
  font-size: 16px;
  margin-right: 40px; 
}
.price,.sellnum {
  color: gray;
}
.price span {
  color: red;
  font-size: 25px;
}
</style>

productcontent.vue

<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>


效果

GIF6.gif

总结

样式的写法那就多种多样了,这个就是随便写一下,如果是这要写商品页面的话可以参考很多商城的样式,也可以加很多效果,我这个写得更像文章页面

element-ui 修改样式

比如修改element-ui的导航菜单active样式,先查看元素,在菜单被选中的时候会多一个is-active的class,所以只要修改这个is-active就可以了,但要注意写在scope里面需要在后面加一个!important

虽然是菜鸟初学者,但还是自恋的留一个github地址吧

github: https://github.com/lyttonlee/learn

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,761评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,953评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,998评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,248评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,130评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,145评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,550评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,236评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,510评论 1 291
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,601评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,376评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,247评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,613评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,911评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,191评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,532评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,739评论 2 335

推荐阅读更多精彩内容

  • 马上就到了高考了。今天我想谈一谈关于学习和高考的话题。 我们首先一定要知道上学跟学习是两个截然不同的概念,学习是一...
    雨影阅读 245评论 0 1
  • 本文参加#未完待续,就要表白#活动,本人承诺,文章内容为原创,且未在其他平台发表过。 愿为君倾尽韶华 执子之手看繁...
    徐原原阅读 417评论 4 12
  • 减肥? 三天打鱼两天晒网。你总是有太多的理由和借口。说的太多,把行动的使劲占据,只能让承诺变成除了麻痹自我之外毫无...
    婵兮壁玥阅读 206评论 0 0
  • 以朴素静默的姿态行走在如画的风景中怕只有一丝的喧嚣也会刺破这圆满的美 这千年的山,是否还有文成公主塞外马蹄的翩翩这...
    嘉温阅读 476评论 14 33
  • 我们接着上面思路继续往下说,那么大家对上面所说的风险比计算的怎么样?那个是需要严格执行的。当你能严格的控制风险率那...
    欧阳壹德阅读 204评论 0 1