index.html
<! DOCTYPE html >
< html lang = " en" >
< head>
< meta charset = " utf-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width,initial-scale=1.0" >
< link rel = " icon" href = " <%= BASE_URL %>favicon.ico" >
< title> <%= htmlWebpackPlugin.options.title %></ title>
< link rel = " stylesheet" href = " ./reset.css" >
< link rel = " stylesheet" href = " https://at.alicdn.com/t/font_3451235_xv5vmac8oe.css" >
</ head>
< body>
< div id = " app" > </ div>
</ body>
</ html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
api文件夹
ajax.js
import axios from "axios"
import store from "@/store"
import nprogress from "nprogress"
import "nprogress/nprogress.css"
const requests = axios. create ( {
baseURL: "/api" ,
timeout: 5000 ,
} ) ;
requests. interceptors. request. use ( ( config) = > {
config. headers. userTempId= store. state. detail. uuid_token;
if ( store. state. user. token) {
config. headers. token= store. state. user. token;
}
nprogress. start ( ) ;
return config;
} ) ;
requests. interceptors. response. use ( ( res) = > {
nprogress. done ( ) ;
return res. data;
} , ( error) = > {
return Promise. reject ( new Error ( 'faile' ) ) ;
} ) ;
export default requests;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
index.js
import axios from "axios" ;
import requests from "./ajax" ;
import mockRequests from "./mockAjax" ;
export const reqCategoryList= ( ) = > {
return requests ( { url: '/product/getBaseCategoryList' , method: 'get' } ) ;
}
export const reqGetBannerList= ( ) = > {
return mockRequests. get ( '/banner' ) ;
}
export const reqGetFloorList= ( ) = > { return mockRequests. get ( '/floor' ) ; }
export const reqGetSearchInfo= ( params) = > requests ( { url: "/list" , method: "post" , data: params} )
export const reqGetDetailInfo= ( id) = > requests ( { url: `/ item/ ${ id} `, methods: "get" } )
export const reqAddorUpdateShopCart= ( skuId, skuNum) = > requests ( { url: `/ cart/ addToCart/ ${ skuId} / ${ skuNum} `, method: "post" } )
export const reqGetCartList= ( ) = > requests ( { url: "/cart/cartList" , method: "get" } )
export const reqDeleteCartById= ( skuId) = > requests ( { url: `/ cart/ deleteCart/ ${ skuId} `, method: "delete" } )
export const reqCheckedById= ( skuId, isChecked) = > requests ( { url: `/ cart/ checkCart/ ${ skuId} / ${ isChecked} `, method: "get" } )
export const reqGetCode= ( phone) = > requests ( { url: `/ user/ passport/ sendCode/ ${ phone} `, method: "get" } ) ;
export const reqUserRegister= ( data) = > requests ( { url: "/user/passport/register" , data, method: "post" } )
export const reqUserLogin= ( data) = > requests ( { url: "/user/passport/login" , data, method: "post" } )
export const reqUSerInfo= ( ) = > requests ( { url: "/user/passport/auth/getUserInfo" , method: "get" } ) ;
export const reqLogout= ( ) = > requests ( { url: "/user/passport/logout" , method: 'get' } )
export const reqAddressInfo= ( ) = > requests ( { url: '/ user/ userAddress/ auth/ findUserAddressList', method: "get" } )
export const reqOrderInfo= ( ) = > requests ( { url: "/order/auth/trade" , method: "get" } ) ;
export const reqSubmitOrder= ( tradeNo, data) = > requests ( { url: `/ order/ auth/ submitOrder? tradeNo= ${ tradeNo} `, data, method: "post" } )
export const reqPayInfo= ( orderId) = > requests ( { url: `/ payment/ weixin/ createNative/ ${ orderId} `, method: 'get' } ) ;
export const reqPayStatus= ( orderId) = > requests ( { url: `/ payment/ weixin/ queryPayStatus/ ${ orderId} `, method: "get" } )
export const reqMyOrderList= ( page, limit) = > requests ( { url: `order/ auth/ ${ page} / ${ limit} `, method: "get" } )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
mockAjax.js
import axios from "axios"
import nprogress from "nprogress"
import "nprogress/nprogress.css"
const requests = axios. create ( {
baseURL: "/mock" ,
timeout: 5000 ,
} ) ;
requests. interceptors. request. use ( ( config) = > {
nprogress. start ( ) ;
return config;
} ) ;
requests. interceptors. response. use ( ( res) = > {
nprogress. done ( ) ;
return res. data;
} , ( error) = > {
return Promise. reject ( new Error ( 'faile' ) ) ;
} ) ;
export default requests;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
mock文件夹
banner.json
[
{
"id" : "1" ,
"imgUrl" : "/images/banner1.jpg"
} ,
{
"id" : "2" ,
"imgUrl" : "/images/banner2.jpg"
} ,
{
"id" : "3" ,
"imgUrl" : "/images/banner3.jpg"
} ,
{
"id" : "4" ,
"imgUrl" : "/images/banner4.jpg"
}
]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
floor.json
[
{
"id" : "001" ,
"name" : "家用电器" ,
"keywords" : [
"节能补贴" ,
"4K电视" ,
"空气净化器" ,
"IH电饭煲" ,
"滚筒洗衣机" ,
"电热水器"
] ,
"imgUrl" : "/images/floor-1-1.png" ,
"navList" : [
{
"url" : "#" ,
"text" : "热门"
} ,
{
"url" : "#" ,
"text" : "大家电"
} ,
{
"url" : "#" ,
"text" : "生活电器"
} ,
{
"url" : "#" ,
"text" : "厨房电器"
} ,
{
"url" : "#" ,
"text" : "应季电器"
} ,
{
"url" : "#" ,
"text" : "空气/净水"
} ,
{
"url" : "#" ,
"text" : "高端电器"
}
] ,
"carouselList" : [
{
"id" : "0011" ,
"imgUrl" : "/images/floor-1-b01.png"
} ,
{
"id" : "0012" ,
"imgUrl" : "/images/floor-1-b02.png"
} ,
{
"id" : "0013" ,
"imgUrl" : "/images/floor-1-b03.png"
}
] ,
"recommendList" : [
"/images/floor-1-2.png" ,
"/images/floor-1-3.png" ,
"/images/floor-1-5.png" ,
"/images/floor-1-6.png"
] ,
"bigImg" : "/images/floor-1-4.png"
} ,
{
"id" : "002" ,
"name" : "手机通讯" ,
"keywords" : [
"节能补贴2" ,
"4K电视2" ,
"空气净化器2" ,
"IH电饭煲2" ,
"滚筒洗衣机2" ,
"电热水器2"
] ,
"imgUrl" : "/images/floor-1-1.png" ,
"navList" : [
{
"url" : "#" ,
"text" : "热门2"
} ,
{
"url" : "#" ,
"text" : "大家电2"
} ,
{
"url" : "#" ,
"text" : "生活电器2"
} ,
{
"url" : "#" ,
"text" : "厨房电器2"
} ,
{
"url" : "#" ,
"text" : "应季电器2"
} ,
{
"url" : "#" ,
"text" : "空气/净水2"
} ,
{
"url" : "#" ,
"text" : "高端电器2"
}
] ,
"carouselList" : [
{
"id" : "0011" ,
"imgUrl" : "/images/floor-1-b01.png"
} ,
{
"id" : "0012" ,
"imgUrl" : "/images/floor-1-b02.png"
} ,
{
"id" : "0013" ,
"imgUrl" : "/images/floor-1-b03.png"
}
] ,
"recommendList" : [
"/images/floor-1-2.png" ,
"/images/floor-1-3.png" ,
"/images/floor-1-5.png" ,
"/images/floor-1-6.png"
] ,
"bigImg" : "/images/floor-1-4.png"
}
]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
mockServer.js
import Mock from 'mockjs'
import banner from "./banner.json"
import floor from "./floor.json"
Mock. mock ( "/mock/banner" , { code: 200 , data: banner} ) ;
Mock. mock ( "/mock/floor" , { code: 200 , data: floor} )
------------------------
App.vue
< template>
< div>
< h1 v- upper= "msg" > < / h1>
< Header> < / Header>
< router- view> < / router- view>
< ! -- 在home,search是显示的,在登录,注册是隐藏的 -- >
< ! -- < Footer v- show= "$route.path=='/home'||$route.path=='/search'" > < / Footer> -- >
< Footer v- show= "$route.meta.show" > < / Footer>
< / div>
< / template>
< script>
import Header from "./components/Header" ;
import Footer from "./components/Footer" ;
export default {
name: "App" ,
data ( ) {
return {
msg: "abc" ,
} ;
} ,
components: {
Header,
Footer,
} ,
mounted ( ) {
this. $store. dispatch ( "categoryList" ) ;
} ,
} ;
< / script>
< style>
< / style>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
main.js
import Vue from 'vue'
import App from './App.vue'
import TypeNav from "@/components/TypeNav"
import Carousel from "@/components/Carousel"
import Pagination from "@/components/Pagination"
Vue. component ( TypeNav. name, TypeNav)
Vue. component ( Carousel. name, Carousel)
Vue. component ( Pagination. name, Pagination)
import router from "@/router"
Vue. config. productionTip = false
import store from './store'
import { reqGetSearchInfo } from './api'
reqGetSearchInfo ( { } )
import '@/mock/mockServe.js' ;
import "swiper/css/swiper.css"
import * as API from "@/api" ;
import { Button, MessageBox } from "element-ui"
Vue. component ( Button. name, Button) ;
Vue. prototype. $msgbox = MessageBox;
Vue. prototype. $alert = MessageBox. alert;
import VueLazyload from 'vue-lazyload'
import atm from "@/assets/1.gif"
Vue. use ( VueLazyload, {
loading: atm
} )
import myPlugins from "@/plugins/myPlugins"
Vue. use ( myPlugins, {
name: 'upper' ,
} ) ;
import "@/plugins/validate" ;
new Vue ( {
render: h = > h ( App) ,
router,
store,
beforeCreate ( ) {
Vue. prototype. $bus = this;
Vue. prototype. $API = API;
}
} ) . $mount ( '#app' )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
babel.config.js
module. exports = {
presets: [
'@vue/cli-plugin-babel/preset'
] ,
"plugins" : [
[
"component" ,
{
"libraryName" : "element-ui" ,
"styleLibraryName" : "theme-chalk"
}
]
]
}
jsconfig.json
{
"compilerOptions" : {
"target" : "es5" ,
"module" : "esnext" ,
"baseUrl" : "./" ,
"moduleResolution" : "node" ,
"paths" : {
"@/*" : [
"src/*"
]
} ,
"lib" : [
"esnext" ,
"dom" ,
"dom.iterable" ,
"scripthost"
]
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
vue.config.js
const { defineConfig } = require ( '@vue/cli-service' )
module. exports = defineConfig ( {
productionSourceMap: false,
transpileDependencies: true,
lintOnSave: false,
devServer: {
proxy: {
'api' : {
target: "http://gmall-h5-api.atguigu.cn" ,
}
}
}
} )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
jsconfig.json
{
"compilerOptions" : {
"baseUrl" : "./" ,
"paths" : {
"@/*" : [
"src/*"
]
}
} ,
"exclude" : [
"node_modules" ,
"dist"
]
}