# uni-hm-shop
**Repository Path**: test_yx/uni-hm-shop
## Basic Information
- **Project Name**: uni-hm-shop
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 4
- **Created**: 2021-06-06
- **Last Updated**: 2021-06-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#### 黑马商城实战项目
##### 项目搭建
+ 利用HBuilder X创建基本项目结构
+ 运行项目
+ 整理基本项目结构,并修改窗口外观
```js
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "黑马商城",
"navigationBarBackgroundColor": "#1989fa",
"backgroundColor": "#F8F8F8"
}
```
##### 配置tabbar
+ 创建tabbar对应的四个页面和图标准备好
+ 将页面路径配置到pages.json中的pages数组中
```js
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index"
},
{
"path": "pages/member/member"
},
{
"path": "pages/cart/cart"
},
{
"path": "pages/search/search"
}
]
```
+ 配置tabbar
```js
{
"tabBar": {
"list": [
{
"pagePath":"pages/index/index",
"text":"首页",
"iconPath":"static/icon/home.png",
"selectedIconPath":"static/icon/home-active.png"
},
{
"pagePath":"pages/member/member",
"text":"会员",
"iconPath":"static/icon/member.png",
"selectedIconPath":"static/icon/member-active.png"
},
{
"pagePath":"pages/cart/cart",
"text":"购物车",
"iconPath":"static/icon/cart.png",
"selectedIconPath":"static/icon/cart-active.png"
},
{
"pagePath":"pages/search/search",
"text":"搜索",
"iconPath":"static/icon/search.png",
"selectedIconPath":"static/icon/search-active.png"
}
]
}
}
```
##### 获取轮播图数据
+ 封装uni.request请求,并挂在到全局
+ 创建util》api.js
```js
// 封装get请求
const baseUrl = "http://localhost:8082"
export const myRequest = (options)=>{
return new Promise((resolve,reject)=>{
uni.request({
method: options.method,
data: options.data,
url: baseUrl+options.url,
success(res) {
if(res.data.status !== 0) {
return uni.showToast({
title: '获取数据失败'
})
}
resolve(res)
},
fail(err) {
uni.showToast({
title: '获取数据失败'
})
reject(err)
}
})
})
}
```
+ 在main.js中导入并挂载到全局
```js
import { myRequest } from './util/api.js'
Vue.prototype.$myRequest = myReques
```
+ 获取轮播图的数据
+ 定义获取轮播图的方法
```js
methods: {
async getSwipers () {
const res = await this.$myRequest({
method: 'GET',
url: '/api/getlunbo'
})
this.swipers = res.data.message
}
}
```
+ 在onLoad中调用该方法
```js
this.getSwipers()
```
##### 实现轮播图的结构和数据渲染
+ 定义轮播图的基本结构
```html
```
+ 样式,在工具中安装scss
```css
```
##### 实现菜单导航结构
+ 引入字体图标文件和初始化样式
```css
```
+ 完成菜单导航基本结构
```
商品列表
图片分享
联系我们
视频专区
```
+ 菜单导航样式
```css
.nav{
display: flex;
align-items: center;
.item{
width: 25%;
text-align: center;
view{
background: $shop-color;
line-height: 120rpx;
width: 120rpx;
height: 120rpx;
border-radius: 90px;
margin:10px auto;
}
text{
font-size: 15px;
}
}
.iconfont{
font-size: 25px;
color: #fff;
height: 50px;
}
.icon-tupian{
font-size: 20px;
}
}
```
##### 实现推荐商品列表
###### 定义基本结构
```html
推荐商品
1299
12990
华为(HUAWEI)荣耀6Plus 16G双4G版
```
###### 美化样式
```css
.hot_goods {
background: #eee;
.tit{
border-top: 2px solid #eee;
border-bottom: 2px solid #eee;
margin-top: 20px;
margin-bottom: 3px;
color: $shop-color;
height: 50px;
line-height: 50px;
text-align: center;
letter-spacing: 20px;
background: #fff;
}
.goods_list {
display: flex;
padding: 0 15rpx;
justify-content: space-between;
overflow: hidden;
flex-wrap: wrap;
.goods_item {
width: 355rpx;
margin-bottom: 15rpx;
background: #fff;
padding: 10px;
box-sizing: border-box;
image{
height: 150px;
width: auto;
mix-width:160px;
margin: 10px auto;
}
.price{
font-size: 18px;
color: red;
padding: 8px 0;
text:nth-child(2){
color: #ccc;
text-decoration: line-through;
margin-left: 10px;
font-size: 13px;
}
}
.name {
font-size: 14px;
}
}
}
}
```
###### 获取数据
+ 定义获取数据的方法
```js
```