名称 | 版本 | 简介 | 功能 |
---|---|---|---|
vue-cli | 4.0.15 | vue脚手架 | 搭建vue项目工具 |
vue | 2.6.10 | 前端框架 | 高效的数据渲染 |
vue-router | 3.1.3 | vue路由 | 前端路由导航 |
axios | 0.19.0 | 网络请求 | 实现对后端数据请求 |
vue-axios | 2.1.5 | axios简单封装 | axios接口使用更加简洁 |
vuetify | 2.1.15 | UI | UI界面组件 |
moment | 2.24.0 | 时间模块 | 日期时间处理 |
本项目使用vue-cli4脚手架搭建,vue-cli安装与项目创建不在详述,下面贴出参考地址:https://blog.csdn.net/mengxianglong123/article/details/102949138
项目搭建成功,自动打开浏览器,界面如图所示:
项目运行效果图:
tips : 关于windows cmd窗口创建项目期间不能使用方向键的问题,给出连接地址:https://blog.csdn.net/gaogzhen/article/details/103601526
初始项目目录结构图:
其中config与register目录为后面自定义添加。下面为目录简单介绍:
自定义目录,为src子目录:
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import vuetify from './plugins/vuetify'
// 导入样式注册器
import './register/assets'
//导入组件注册器
import './register/component'
// 导入全局过滤器注册器
import './register/filter'
Vue.config.productionTip = false
new Vue({
el: '#app',
router, // 路由组件注册
vuetify, // vuetify注册
render: h => h(App)
}).$mount('#app')
const baseUrl = 'http://api.leyou.com'
const config = {
locale: 'zh-CN', // en-US, zh-CN
url: baseUrl,
debug: {
http: false // http request log
},
api: `${baseUrl}/api`,
theme:{ // vuetify主题
primary: "#2196F3",
secondary: "#455A64",
accent: "#9c27b0",
error: "#f44336",
warning: "#FFC107",
info: "#64B5F6",
success: "#4caf50"
},
isDark:true,
unitOption:[ // 单位配置
{ header: '长度' },
{ value: 'mm'},
{ value: 'cm'},
{ value: 'dm'},
{ value: 'm'},
{ value: '寸'},
{ value: '英寸'},
{ value: '尺'},
{ divider: true },
{ header: '重量' },
{ value: 'mg'},
{ value: 'g'},
{ value: 'kg'},
{ value: 't'},
{ divider: true },
{ header: '像素' },
{ value: '万像素'},
{ divider: true },
{ header: '频率' },
{ value: 'Hz'},
{ value: 'mHz'},
{ value: 'gHz'},
{ divider: true },
{ header: '存储' },
{ value: 'KB'},
{ value: 'MB'},
{ value: 'GB'},
{ divider: true },
{ header: '电压' },
{ value: 'V'},
{ value: 'KV'},
{ divider: true },
{ header: '电池容量' },
{ value: 'mAh'},
{ divider: true },
{ header: '功率' },
{ value: 'w'},
{ value: 'Kw'},
{ divider: true },
{ header: '电流' },
{ value: 'μA'},
{ value: 'mA'},
{ value: 'A'},
{ divider: true },
{ header: '电阻' },
{ value: 'Ω'},
{ value: 'KΩ'},
{ value: 'A'},
{ divider: true },
]
}
export default config
路由组件可以直接导入,也可以通过懒加载实现,这里推荐懒加载实现。本例只有一个组件-Category.vue组件使用懒加载,如果要实现性懒加载,照做就可以。
本例router/index.js源代码@3.2.1.1:
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout.vue'
import Reports from '../views/home/Reports.vue'
import Brand from '../views/item/Brand.vue'
// import Category from '../views/item/Category.vue' // 下面懒加载模式
import GoodsList from '../views/item/GoodsList.vue'
import Specification from '../views/item/Specification.vue'
import Statistics from '../views/user/Statistics.vue'
import UserList from '../views/user/UserList.vue'
import Statistics1 from '../views/sale/Statistics.vue'
import Order from '../views/sale/Order.vue'
import Logistics from '../views/sale/Logistics.vue'
import Promotion from '../views/sale/Promotion.vue'
import AuthList from '../views/authority/AuthList.vue'
import Role from '../views/authority/Role.vue'
import Member from '../views/authority/Member.vue'
Vue.use(VueRouter)
const routes = [{
path: '/',
name: 'layout',
component: Layout,
redirect: '/index/report', // 默认跳转首页管理统计页面
children: [
{
name: 'reports',
path: 'index/report',
component: Reports
},
{
name: 'brand',
path: 'item/brand',
component: Brand
},
{
name: 'category',
path: 'item/category',
component: () => import('@/views/item/Category.vue') // 懒加载模式
},
{
name: 'goodsList',
path: 'item/goodsList',
component: GoodsList
},
{
name: 'specification',
path: 'item/specification',
component: Specification
},
{
name: 'statistics',
path: 'user/statistics',
component: Statistics
},
{
name: 'userList',
path: 'user/userList',
component: UserList
},
{
name: 'statistics1',
path: 'sale/statistics',
component: Statistics1
},
{
name: 'order',
path: 'sale/order',
component: Order
},
{
name: 'logistics',
path: 'sale/logistics',
component: Logistics
},
{
name: 'promotion',
path: 'sale/promotion',
component: Promotion
},
{
name: 'authList',
path: 'authority/authList',
component: AuthList
},
{
name: 'role',
path: 'authority/role',
component: Role
},
{
name: 'member',
path: 'authority/member',
component: Member
},
]
}]
const router = new VueRouter({
routes
})
export default router
main.js 相关源代码@3.2.1.2:
import Vue from 'vue'
import App from './App.vue'
import router from './router' // 路由组件导入
import vuetify from './plugins/vuetify'
// 导入样式注册器
import './register/assets'
//导入组件注册器
import './register/component'
// 导入全局过滤器注册器
import './register/filter'
Vue.config.productionTip = false
new Vue({
el: '#app',
router, // 路由组件注册
vuetify,
render: h => h(App)
}).$mount('#app')
import Vue from 'vue'
import Vuetify from 'vuetify'
import config from '../config/config.js'
Vue.use(Vuetify)
const opts = {
theme: config.theme, // 主题
icons: { // 字体图标
iconfont: ['mdi']
}
}
export default new Vuetify(opts)
// axios 模块
import axios from 'axios'
import config from '../config/config.js'
// 创建实例,配置默认值
const http = axios.create()
// 配置基路径
http.defaults.baseURL = config.api
export default http
// 导入字体图标
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import '@mdi/font/css/materialdesignicons.css'
// 导入vuetify样式
import 'vuetify/dist/vuetify.min.css'
import '../assets/material.css'
// 导入element-ui样式
import 'element-ui/lib/theme-chalk/index.css'
// 导入ivewer样式
import "iview/dist/styles/iview.css"
import Vue from 'vue'
import VueAxios from 'vue-axios'
import Http from '../plugins/http'
import CustomComponent from '../components/custom-component'
import config from '../config/config'
Vue.use(VueAxios, Http) // 对axios简单封装
Vue.use(CustomComponent) // 自定义组件注册
Vue.prototype.$config = config // 挂载基础配置
import Vue from 'vue'
import Moment from 'moment'
// 定义全局过滤器:日期时间格式化过滤器
Vue.filter('dateFormat', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
return Moment(dataStr).format(pattern)
})
后记 :本项目为参考某马视频thinkphp5.1-乐优商城前后端项目开发,相关视频及配套资料可自行度娘或者联系本人。上面为自己编写的开发文档,持续更新。欢迎交流,本人QQ:806797785