🍖06 创建应用(app),表(model)及路由配置
一.创建前台项目及项目目录重构
创建一个 Vue 项目, 前面文章详细介绍了如何创建一个 Vue 项目👉Vue-cli 创建项目
- 整体流程
# 1.傻瓜式安装node:
官网下载:https://nodejs.org/zh-cn/
# 2.安装cnpm:
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 3.安装vue最新脚手架:
>: cnpm install -g @vue/cli
## 注:如果2、3步报错,清除缓存后重新走2、3步
>: npm cache clean --force
# 4.创建项目
在目标目录新建luffy文件夹
cd 建立的luffy文件夹
vue create luffycity
二.文件修订
1.将目录中非配置文件的多余文件删除
2.将组件文件或其他配置文件内无关内容删除
- App.vue : 根组件
<template>
<div id="app">
<router-view/>
</div>
</template>
- router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter);
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/home',
redirect: '/',
},
];
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
- Home.vue
<template>
<div class="home">
</div>
</template>
<script>
export default {
name: 'home',
components: {
},
}
</script>
三.全局配置 : 全局样式及配置文件
1.global.css
- 清除默认样式
/* 声明全局样式和项目的初始化样式 */
body, h1, h2, h3, h4, h5, h6, p, table, tr, td, ul, li, a, form, input, select, option, textarea {
margin: 0;
padding: 0;
font-size: 15px;
}
a {
text-decoration: none;
color: #333;
}
ul {
list-style: none;
}
table {
border-collapse: collapse; /* 合并边框 */
}
2.settings.js
export default {
base_url: 'http://127.0.0.1:8000'
}
3.main.js
// 配置全局样式
import '@/assets/css/global.css'
// 配置全局自定义设置
import settings from '@/assets/js/settings'
Vue.prototype.$settings = settings;
// 在所有需要与后台交互的组件中:this.$settings.base_url + '再拼接具体后台路由'

浙公网安备 33010602011771号