目錄
一、前言
二、功能效果圖
1.首頁
2.分類
?3.活動
4.我的
?5.商品詳情
6.購物車
三、代碼實現(xiàn)
1.項目結(jié)構(gòu)截圖 uni-app,Hbuilder
2.首頁源碼
3.數(shù)據(jù)模擬通訊
四、總結(jié)
一、前言
參考“網(wǎng)易嚴選”小程序
項目采用傳統(tǒng)vue項目結(jié)構(gòu),即uni-app打包和運行成小程序,使用HBuilder開發(fā)工具開發(fā)項目,通過運行啟動“微信開發(fā)者工具”完成項目啟動。
二、功能效果圖
1.首頁
?
2.分類
?3.活動
4.我的
?5.商品詳情
6.購物車
代碼動態(tài)實現(xiàn)商品購物車的增刪改查等操作。
三、代碼實現(xiàn)
1.項目結(jié)構(gòu)截圖 uni-app,Hbuilder
2.首頁源碼
<template>
<view class="Header">
<view class="myHeader">
<view class="logos">
網(wǎng)易嚴選
</view>
<view class="searchs">
<uni-icons type="search" size="30"></uni-icons><input type="text" name="" id=""
placeholder="請輸入想搜索的商品..." @tap="goShowContract">
</view>
<view class="search-button">
<view class="button" @click="onSearch">取消</view>
</view>
</view>
<!-- 輪播圖 -->
<view class="backgroundBanner">
<view class="banner">
<swiper autoplay="true" :interval="2000" :duration="500" circular="true" indicator-active-color="#fff"
easing-function="true" indicator-dots='true'>
<swiper-item v-for="(item, index) in bannerList" :key="index">
<img :src="item.url"></img>
</swiper-item>
</swiper>
</view>
</view>
<!-- 分類部分 -->
<view class="cates">
<view class="cate-item" v-for="(cateItem,cateIndex) in cateList" :key="cateIndex" @tap="selPage(cateItem)">
<image :src="cateItem.cateUrl"></image>
<text>{{cateItem.cateName}}</text>
</view>
</view>
<hr>
<view class="time">
<view class="timeTop">
<view class="logo">
<image src="../../static/zhong.jpg" mode=""></image>
<!-- <uni-icons type="notification-filled" size="20"></uni-icons> -->
<text>限時秒購</text>
</view>
<view class="timeFinish">
<text>距結(jié)束</text>
<uni-countdown :day="1" :hour="2" :minute="30" :second="0" color="#FFFFFF"
background-color="#007AFF" />
</view>
</view>
<view class="timeBottom">
<view class="timeItem" v-for="(timeItem,timeIndex) in timeList" :key="timeIndex">
<image :src="timeItem.timeUrl"></image>
<view class="timeText">
<text class="timeText1">¥{{timeItem.timeText1}}</text>
<text class="timeText2">¥{{timeItem.timeText2}}</text>
</view>
</view>
</view>
<hr>
<scroll-view scroll-x class="myNav">
<view v-for="(item,index) in indexTypes" :key="index" @tap="selType(item)" :class="'item '+(typeId===item.id?'active':'')" style='font-size: 30rpx;'>{{item.name}}</view>
</scroll-view>
<index-type ref="indexType"></index-type>
</view>
</view>
</view>
</template>
<script>
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'
import indexType from '@/components/index_type.vue'
export default {
components:{
indexType,
},
data() {
return {
typeId: 0,
cateList: [{
cateId: 0,
cateUrl: "../../static/zhong.jpg",
cateName: '限時秒殺',
path:''
},
{
cateId: 0,
cateUrl: '../../static/che.jpg',
cateName: '斷貨清倉',
path:'./okoko'
},
{
cateId: 0,
cateUrl: "../../static/yi.jpg",
cateName: '寶藏女裝',
},
{
cateId: 0,
cateUrl: "../../static/b3.jpg",
cateName: '多多果園',
},
{
cateId: 0,
cateUrl: "../../static/9.9.jpg",
cateName: '9塊9特賣',
},
{
cateId: 0,
cateUrl: "../../static/1a.jpg",
cateName: '簽到',
},
{
cateId: 0,
cateUrl: "../../static/yao.jpg",
cateName: '醫(yī)藥館',
},
{
cateId: 0,
cateUrl: "../../static/54e.jpg",
cateName: '省錢月卡',
},
],
// //商品實例圖
timeList: [{
time: 0,
timeUrl: '../../static/7b.jpg',
timeText1: '388',
timeText2: '720',
},
{
time: 0,
timeUrl: '../../static/345d.jpg',
timeText1: '18',
timeText2: '39',
},
{
time: 0,
timeUrl: '../../static/3d.jpg',
timeText1: '3888',
timeText2: '3889',
},
{
time: 0,
timeUrl: '../../static/bing.jpg',
timeText1: '12.9',
timeText2: '18',
},
],
bannerList: [{
id: 1,
url: '../../static/temp1.jpg'
},
{
id: 2,
url: '../../static/temp2.jpg'
},
{
id: 3,
url: '../../static/temp3.jpg'
},
{
id: 4,
url: '../../static/temp4.jpg'
},
{
id: 5,
url: '../../static/temp5.jpg'
},
],
}
},
computed:{
...mapState([
'products',
'indexTypes'
])
},
mounted() {
this.typeId = this.indexTypes[0].id;
this.$refs.indexType.initProduct(this.indexTypes[0]);
},
methods: {
goShowContract() {
uni.navigateTo({
url: '/pages/index/show-contract'
})
},
selPage(cateItem){
// uni.navigateTo({
// url:cateItem.path,
// })
},
//選擇分類
selType(item){
this.typeId = item.id;
this.$refs.indexType.initProduct(item);
}
}
}
</script>
<style lang="scss" scoped>
* {
margin: 0;
padding: 0;
}
.myHeader {
display: flex;
padding: 10rpx;
align-items: center;
.logos {
width: 140rpx;
height: 40rpx;
}
.searchs {
border: 1px solid black;
border-radius: 10rpx;
flex: 1;
margin: 0 10rpx;
width: 80rpx;
padding-left: 14rpx;
display: flex;
align-items: center;
padding: 4rpx 10rpx;
vertical-align: top;
}
.btn {
width: 80rpx;
text-align: center;
}
}
.myNav {
white-space: nowrap;
display: flex;
color: #333;
box-sizing: border-box;
height: 80rpx;
.item {
flex: 1;
margin: 10rpx 20rpx;
display: inline-block;
&.active {
color: #ff5555;
border-bottom: 2px solid #ff5555;
font-size: 24px;
}
}
.item:hover {
display: inline-block;
color: #ff5555;
border-bottom: 2px solid #ff5555;
}
}
.backgroundBanner {
padding: 0 10rpx;
box-sizing: border-box;
}
.banner {
width: 100%;
margin: 0 auto;
}
.banner swiper {
height: calc(750rpx / 1.9); //calc(屏幕寬度 / (圖片寬度 / 圖片高度))
}
.banner img {
width: 100%;
height: 100%;
}
.cates {
width: 100%;
height: 200rpx;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-around;
.cate-item {
width: 20%;
height: 160rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
image {
width: 100rpx;
height: 100rpx;
}
}
}
.cates {
width: 100%;
height: 400rpx;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-around;
flex-wrap: wrap;
.cate-item {
width: 22%;
height: 160rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
// flex-flow: wrap;
image {
width: 100rpx;
height: 100rpx;
}
}
}
.time {
width: 100%;
background-color: #fff;
margin-top: 20rpx;
.timeTop {
height: 80rpx;
display: flex;
justify-content: space-between;
align-items: center;
margin-left: 20rpx;
.logo {
image {
width: 30rpx;
height: 30rpx;
margin-right: 10rpx;
}
text {
font-size: 16px;
}
}
.timeFinish {
margin-right: 20rpx;
display: flex;
align-items: center;
text {
font-size: 14px;
}
}
}
.timeBottom {
width: 100%;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
.timeItem {
width: 25%;
justify-content: space-around;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
image {
width: 160rpx;
height: 160rpx;
}
.timeText {
display: flex;
justify-content: space-between;
font-size: 14px;
.timeText2 {
color: #9F9F9F;
text-decoration: line-through;
}
}
}
}
}
</style>
3.數(shù)據(jù)模擬通訊
通過vuex實現(xiàn)數(shù)據(jù)通訊共享和管理
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
//公共的變量,這里的變量不能隨便修改,只能通過觸發(fā)mutations的方法才能改變
//首頁分類
indexTypes:[
{id: 1,name: '商品推薦'},
{id: 2,name: '配飾'},
{id: 3,name: '包包'},
{id: 4,name: '鞋子'},
{id: 5,name: '裙子'},
{id: 6,name: '飲品'},
{id: 7,name: '衣服'}
],
//分類菜單
allTypes:[
{id: 11,name: '推薦'},
{id: 12,name: '箱包'},
{id: 13,name: '男裝'},
{id: 14,name: '女裝'},
{id: 15,name: '鞋子'},
{id: 16,name: '褲子'},
{id: 17,name: '食品'},
{id: 18,name: '維修'},
{id: 19,name: '機票'},
{id: 20,name: '圖書'},
{id: 21,name: '寵物'},
],
//活動商品 商品主鍵id
activeProducts:[
1,2,3,4,5
],
//全部商品
products: [{
id:1,
typeIds:[1,11],
cover: require('../../static/0fd.jpg'),
imgList: [
'https://img11.360buyimg.com/n1/s450x450_jfs/t1/71831/14/25245/39959/6487c621Fca760cf2/769dd8bcf43d82c1.jpg',
'https://img.pddpic.com/mms-material-img/2022-08-11/cd9c638d-dac2-474a-aad2-0f141c146102.jpeg.a.jpeg?imageMogr2/quality/90/format/webp',
'https://img.pddpic.com/mms-material-img/2022-08-11/b0827f91-083a-4b5b-9461-64e6d6789fcf.jpeg.a.jpeg?imageMogr2/quality/90/format/webp'
],
name: '聯(lián)想拯救者Y9000P i7/RTX3060 2022款16英寸電競游戲筆記本電腦',
title: '電腦',
price: 2000,
oldprice: 5000,
saleNumMonth: 120,
saleNumTotal: 2000,
types: [{
name: '類型',
items: [{
id: 1,
name: '13.3英寸 M1芯片 8+7核 8G+256G'
},
{
id: 2,
name: '13.3英寸 M1芯片 8+7核 8G+512G'
},
{
id: 3,
name: '13.3英寸 M1芯片 8+7核 16G+256G'
},
{
id:4,
name: '13.3英寸 M1芯片 8+7核 16G+512G'
}
],
},
{
name: '數(shù)量',
items: [{
id: 1,
name: '英特爾官方21代'
}, {
id: 2,
name: '英特爾官方18代'
}, {
id: 3,
name: '英特爾官方19代'
}]
}
]
},
{
id:2,
typeIds:[1,11],
cover: require('../../static/13d.jpg'),
imgList: [
"https://img.pddpic.com/mms-material-img/2021-12-10/6b514989-49fb-4112-b636-33fc82cb1641.jpeg.a.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2022-01-05/6fbb05da-e1ba-4bee-985a-300cdd7ad2e9.jpeg.a.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2021-12-10/21e55b15-a17d-4668-b8a9-9b8616f11cb2.jpeg.a.jpeg?imageMogr2/quality/90/format/webp"
],
name: '保鮮膜([食品級認證)',
title:'保鮮膜',
price: 12.99,
oldprice: 20.80,
saleNumMonth: 120,
saleNumTotal: 2000,
types: [{
name: '型號',
items: [{
id: 1,
name: '1卷寬30厘米6.25斤'
},
{
id: 2,
name: '1卷寬50厘米7斤'
},
{
id: 3,
name: '整箱寬50厘米4卷28斤'
},
{
id:4,
name: '整箱4卷寬50厘米重40斤約720米'
}
],
},
{
name: '數(shù)量',
items: [{
id: 1,
name: '3包'
}, {
id: 2,
name: '5包'
}, {
id: 3,
name: '10包'
}]
}
]
},
{
id:3,
typeIds:[1,11],
cover: require('../../static/8537c.jpg'),
imgList: [
"https://img.pddpic.com/mms-material-img/2022-05-28/3329312a-b971-4990-af80-6e15113b0600.jpeg.a.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2022-05-28/e12d134d-c2d8-4aec-8dc3-0e9ff80befd5.jpeg.a.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2022-05-28/1510e448-2d5b-4398-a692-ff679e2587e8.jpeg.a.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2022-05-28/248a3ffb-b4ce-4529-a7a4-8f0c97a4b331.jpeg.a.jpeg?imageMogr2/quality/90/format/webp"
],
name: '男士斜挎包潮牌ins工裝風日系休閑男包大容量單肩包個性郵差包潮',
title:'斜挎包',
price: 33.00,
oldprice: 40.75,
saleNumMonth: 120,
saleNumTotal: 2000,
types: [{
name: '顏色',
items: [
{
id: 1,
name: '大板黑色'
},
{
id: 2,
name: '灰色'
},
{
id: 3,
name: '藍色'
},
{
id:4,
name: '白色'
}
],
},
]
},
{
id:4,
typeIds:[1,11],
cover: require('../../static/fa98.jpg'),
imgList: [
"https://img.pddpic.com/openapi/images/2020-04-27/4cd766b88b0a4e9e8fbebaa221de7b58.jpg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/openapi/images/2020-04-27/c2090bace7f938f02819fca05e17c4e7.jpg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/openapi/images/2020-04-27/1492ab8ba1e76cca387583c80180d65e.jpg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/openapi/images/2020-04-27/13b1af9176580b3e7a035871f4456594.jpg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/openapi/images/2020-04-27/793db583c0d598c13124af5991f7794e.jpg?imageMogr2/quality/90/format/webp"
],
name: '高級感韓版原創(chuàng)ins個性多層斜挎包2023夏季新款包包女單肩鏈條包',
title:'休閑 仙女',
price: 38.39,
oldprice: 57.80,
saleNumMonth: 120,
saleNumTotal: 2000,
types: [{
name: '顏色',
items: [
{
id: 1,
name: '大板黑色'
},
{
id: 2,
name: '灰色'
},
{
id: 3,
name: '紅色'
},
{
id:4,
name: '粉色'
},
{
id:5,
name: '白色'
},
],
},
]
},
{
id:5,
typeIds:[1,11],
cover: 'https://img.pddpic.com/goods/images/2020-06-10/52fd0f70-671c-4ab0-a867-094d8301d4e5.jpeg?imageMogr2/quality/90/format/webp',
imgList: [
"https://img.pddpic.com/goods/images/2020-06-10/52fd0f70-671c-4ab0-a867-094d8301d4e5.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2020-06-04/a12fe65d-ee77-4b1c-b183-7ce735fb1342.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2020-06-04/cf0eb9da-efb7-4f24-9703-6450b792b4ec.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/mms-material-img/2020-06-04/911b4c63-1212-46e7-a1eb-038b983553b0.jpeg?imageMogr2/quality/90/format/webp",
"https://img.pddpic.com/goods/images/2020-06-10/f7e45e61-0a72-4ac9-8f56-f422327799b9.jpeg?imageMogr2/quality/90/format/webp"
],
name: '【馴龍士】夏季新款冰絲套裝男休閑運動短袖男士大碼七分褲兩件套',
title:'馴龍士',
price: 99.99,
oldprice: 120.80,
saleNumMonth: 120,
saleNumTotal: 2000,
types: [{
name: '顏色',
items: [
{
id: 1,
name: '軍綠色'
},
{
id: 2,
name: '灰色'
},
{
id: 3,
name: '黑色'
},
],
},
]
}
],
},
mutations: {
//相當于同步的操作
getarray(state, count) {
var shuffled = state.timesList.slice(0),
i = state.timesList.length,
min = i - count,
temp,
index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
},
actions: {
//相當于異步的操作,不能直接改變state的值,只能通過觸發(fā)mutations的方法才能改變
}
})
export default store
四、總結(jié)
項目功能完整,后續(xù)可能將不斷升級。
關(guān)注作者,及時了解更多好項目!
作者主頁也有更多好項目分享!
獲取源碼或如需幫助,可通過博客后面名片+作者即可!文章來源:http://www.zghlxwxcb.cn/news/detail-772326.html
?其他作品集合文章來源地址http://www.zghlxwxcb.cn/news/detail-772326.html
- 《Springboot+Spring Security+OAuth2+redis+mybatis-plus+mysql+vue+elementui實現(xiàn)請假考勤系統(tǒng)》
- 《vue+element實現(xiàn)電商商城禮品代發(fā)網(wǎng),商品、訂單管理》
- 《vue+vant2完美實現(xiàn)香奈兒移動端商城網(wǎng)站》
- 《vue+elementui實現(xiàn)聯(lián)想購物商城,樣式美觀大方》
- 《vue+elementui實現(xiàn)英雄聯(lián)盟道具城》
- 《vue+elementui實現(xiàn)app布局小米商城,樣式美觀大方,功能完整》
- 《vue完美模擬pc版快手,實現(xiàn)短視頻,含短視頻詳情播放》
- 《vue+element實現(xiàn)美觀大方好看的音樂網(wǎng)站,仿照咪咕音樂網(wǎng)》?????
到了這里,關(guān)于uni-app基于vue實現(xiàn)商城小程序的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!