给导航添加到了数据中 增加了点击事件。创建商品页面,goods/goods

    1. <template>
    2. <view class='home'>
    3. <swiper indicator-dots circular>
    4. <swiper-item v-for='item in swipers' :key='item.id'>
    5. <image :src='item.img'></image>
    6. </swiper-item>
    7. </swiper>
    8. <!--导航-->
    9. <view class='nav'>
    10. <view class='nav_item' v-for="(item,index) in navs" :key='index' @click="navItemClick(item.path)">
    11. <view :class='item.icon'></view>
    12. <text>{{item.title}}</text>
    13. </view>
    14. </view>
    15. <!--推荐商品-->
    16. <view class='hot_goods'>
    17. <view class='tit'>推荐商品</view>
    18. <view class='goods_list'>
    19. <view class='goods_item' v-for="item in goods" :key="item.id">
    20. <image :src='item.img_url'></image>
    21. <view class='price'>
    22. <text>¥{{item.sell_price}}</text>
    23. <text>¥{{item.market_price}}</text>
    24. </view>
    25. <view class="name">
    26. {{item.title}}
    27. </view>
    28. </view>
    29. </view>
    30. </view>
    31. </view>
    32. </template>
    33. <script>
    34. export default {
    35. data() {
    36. return {
    37. swipers: [],
    38. goods: [],
    39. navs:[
    40. {
    41. icon:'iconfont icon-ziyuan',
    42. title:'黑马超市',
    43. path:'/pages/goods/goods'
    44. },
    45. {
    46. icon:'iconfont icon-guanyuwomen',
    47. title:'联系我们',
    48. path:'/pages/contact/contact'
    49. },
    50. {
    51. icon:'iconfont icon-tupian',
    52. title:'社区图片',
    53. path:'/pages/pics/pics'
    54. },
    55. {
    56. icon:'iconfont icon-shipin',
    57. title:'学习视频',
    58. path:'/pages//videos/videos'
    59. }
    60. ]
    61. }
    62. },
    63. onLoad() { //监听页面加载
    64. this.getSwiper()
    65. this.getHotGoods()
    66. },
    67. methods: {
    68. //获取轮播数据
    69. async getSwiper() {
    70. const res = await this.$myRequest({
    71. url: '/api/getlunbo'
    72. })
    73. this.swipers = res.data.message
    74. },
    75. //获取热门商品列表数据
    76. async getHotGoods() {
    77. const res = await this.$myRequest({
    78. url: '/api/getgoods?pageindex=1'
    79. })
    80. this.goods = res.data.message
    81. },
    82. //导航点击的处理
    83. navItemClick(url){
    84. //console.log('跳转')
    85. uni.navigateTo({
    86. url
    87. })
    88. }
    89. }
    90. }
    91. </script>
    92. <style lang="scss">
    93. .home {
    94. swiper {
    95. width: 750rpx;
    96. height: 380rpx;
    97. image {
    98. height: 100%;
    99. width: 100%;
    100. }
    101. }
    102. .nav {
    103. display: flex;
    104. .nav_item {
    105. width: 25%;
    106. text-align: center;
    107. view {
    108. width: 120rpx;
    109. height: 120rpx;
    110. background-color: $shop-color;
    111. border-radius: 60rpx;
    112. margin: 10px auto;
    113. line-height: 120rpx;
    114. color: #fff;
    115. font-size: 50rpx;
    116. }
    117. .icon-tupian {
    118. font-size: 45rpx;
    119. }
    120. text {
    121. font-size: 30rpx;
    122. }
    123. }
    124. }
    125. .hot_goods {
    126. background: #eee;
    127. overflow: hidden;
    128. margin-top: 10px;
    129. .tit {
    130. height: 50px;
    131. line-height: 50px;
    132. color: $shop-color;
    133. text-align: center;
    134. letter-spacing: 20px;
    135. font-size: 20px;
    136. margin: 7rpx 0;
    137. background: #fff;
    138. }
    139. .goods_list {
    140. padding: 0 15rpx;
    141. display: flex;
    142. flex-wrap: wrap;
    143. justify-content: space-between;
    144. .goods_item {
    145. background: #fff;
    146. width: 355rpx;
    147. margin: 10rpx 0;
    148. padding: 15rpx;
    149. box-sizing: border-box; //不会撑开盒子了
    150. image {
    151. width: 95%;
    152. height: 200px;
    153. display: block;
    154. margin: 0 auto; //上面下面实现居中
    155. }
    156. .price {
    157. color: $shop-color;
    158. font-size: 36rpx;
    159. margin: 5rpx 0;
    160. text:nth-child(2) {
    161. color: #CCC;
    162. font-size: 28rpx;
    163. margin-left: 17rpx;
    164. text-decoration: line-through;
    165. }
    166. }
    167. .name {
    168. font-size: 22rpx;
    169. line-height: 40rpx;
    170. }
    171. }
    172. }
    173. }
    174. }
    175. </style>

    goods页面

    1. <template>
    2. <view>
    3. 商品列表
    4. </view>
    5. </template>
    6. <script>
    7. export default {
    8. data() {
    9. return {
    10. };
    11. }
    12. }
    13. </script>
    14. <style lang="scss">
    15. </style>