hoverSearch.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="scroll-show">
  3. <div class="content clearfix">
  4. <cateNav class="cate" :showNavBar="false"></cateNav>
  5. <Search class="search-con" :showLogo="false" :showTag="false"></Search>
  6. <Icon type="ios-cart-outline" @click="goCartList" class="cart-icon" @mouseenter.native="getCartList" />
  7. <i class="cart-badge">{{cartNum < 100 ? cartNum : '99'}}</i>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import {cartCount} from '@/api/cart.js'
  13. import storage from '@/plugins/storage.js';
  14. export default {
  15. data () {
  16. return {
  17. userInfo: {} // 用户信息
  18. }
  19. },
  20. computed: {
  21. cartNum () { // 购物车数量
  22. return this.$store.state.cartNum
  23. }
  24. },
  25. methods: {
  26. goCartList () {
  27. let routerUrl = this.$router.resolve({
  28. path: '/cart'
  29. })
  30. window.open(routerUrl.href, '_blank')
  31. },
  32. getCartList () { // 获取购物车列表
  33. if (storage.getItem('userInfo')) {
  34. cartCount().then(res => {
  35. this.$store.commit('SET_CARTNUM', res.result)
  36. this.Cookies.setItem('cartNum', res.result)
  37. })
  38. }
  39. }
  40. },
  41. mounted () {
  42. if (storage.getItem('userInfo')) {
  43. this.userInfo = JSON.parse(storage.getItem('userInfo'));
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang="scss" scoped>
  49. .content{
  50. width: 1200px;
  51. height: 40px;
  52. margin: 10px auto;
  53. position: relative;
  54. }
  55. .cate {
  56. float: left;
  57. width: 200px!important;
  58. }
  59. .search-con{
  60. float: left;
  61. width: 800px;
  62. overflow: hidden;
  63. margin-top: -27px;
  64. }
  65. .cart-icon {
  66. width: 30px;
  67. float: left;
  68. font-size: 25px;
  69. margin-top: 8px;
  70. color: $theme_color;
  71. z-index: 1;
  72. position: relative;
  73. &:hover{
  74. cursor: pointer;
  75. }
  76. }
  77. .cart-badge {
  78. position: absolute;
  79. font-style: normal;
  80. right: 165px;
  81. display: block;
  82. background-color: $theme_color;
  83. color: #fff;
  84. font-size: 12px;
  85. width: 17px;
  86. height: 17px;
  87. border-radius: 10px;
  88. line-height: 17px;
  89. text-align: center;
  90. z-index: 5;
  91. top: 3px;
  92. }
  93. </style>