一:创建项目
1.创建vue项目
注意:这里的项目名只能全部小写
vue create luffycity
2.剩余创建步骤
注意:先看这里!
创建项目的时候,如果觉得自己代码写得很规范的,可以开启ESLint
如果是刚开始接触Vue,建议在项目创建的时候,不要开启ESLint
开启了ESLint,就相当于开启了严格模式,以下情况都会报错:
多1个,
多1个空格
缩进不正确
存在:已经导入 但未被使用的组件
etc…
具体创建步骤:看以前博客
二:配置
1.目录结构
2.文件解析
① App.vue(初始)
复制代码
复制代码
Home这个相当于a链接
不同之处:
因为Vue是单页面开发,router-link只会在组件之间来回切换
a链接会跳转到其他页面
② src/router/index.js(初始)
复制代码
import Vue from ‘vue’
import VueRouter from ‘vue-router’
import Home from ‘…/views/Home.vue’ // 导入Home组件
Vue.use(VueRouter)
const routes = [
{
path: ‘/’, // 设置跟路由路径:/
name: ‘Home’,
component: Home // 跟路由组件为Home
},
{
path: ‘/about’,
name: ‘About’,
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: “about” */ ‘…/views/About.vue’)
}
]
const router = new VueRouter({
mode: ‘history’,
base: process.env.BASE_URL,
routes
})
export default router
复制代码
③ src/main.js
整个项目的入口js文件
这是1个很重要的配置文件
配置了根组件、路由跳转
可以全局导入CSS、JS
导入的CSS和JS可以来自assets,也可以来自node_modules(推荐)
复制代码
import Vue from ‘vue’
import App from ‘./App.vue’
import router from ‘./router’
import store from ‘./store’
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount(’#app’)
复制代码
3.目录配置
目录文件修改
在src的assets下创建css、js、img文件夹
删除src的components下的所有文件
4.安装、导入配置
以下安装,如果用npm觉得速度慢的,可以用cnpm安装
① 配置全局初始化CSS样式
在src/assets/css下创建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; /* 合并边框 */
}
复制代码
配置:main.js
// 使用 global.css
import ‘./assets/css/global.css’
② Axios - 用于前后端交互
安装
npm install axios
配置:main.js
// Axios 配置
import axios from ‘axios’
Vue.prototype.
a
x
i
o
s
=
a
x
i
o
s
;
③
v
u
e
−
c
o
o
k
i
e
s
安
装
n
p
m
i
n
s
t
a
l
l
v
u
e
−
c
o
o
k
i
e
s
配
置
:
m
a
i
n
.
j
s
/
/
v
u
e
−
c
o
o
k
i
e
配
置
i
m
p
o
r
t
c
o
o
k
i
e
s
f
r
o
m
′
v
u
e
−
c
o
o
k
i
e
s
′
V
u
e
.
p
r
o
t
o
t
y
p
e
.
axios = axios; ③ vue-cookies 安装 npm install vue-cookies 配置:main.js // vue-cookie 配置 import cookies from 'vue-cookies' Vue.prototype.
axios=axios;③vue−cookies安装npminstallvue−cookies配置:main.js//vue−cookie配置importcookiesfrom′vue−cookies′Vue.prototype.cookies = cookies
④ Element UI - 饿了么团队开发的 1个好看的基于Vue的UI
安装
cnpm install element-ui
配置:main.js
// ElementUI 配置
import ElementUI from ‘element-ui’;
import ‘element-ui/lib/theme-chalk/index.css’;
Vue.use(ElementUI);
⑤ JQuery
Vue不推荐使用JQuery,所以引用的方式和其他的不大一样
安装
npm install jquery
在项目根路径下创建:vue.config.js
复制代码
const webpack = require(“webpack”);
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
:
"
j
q
u
e
r
y
"
,
j
Q
u
e
r
y
:
"
j
q
u
e
r
y
"
,
"
w
i
n
d
o
w
.
j
Q
u
e
r
y
"
:
"
j
q
u
e
r
y
"
,
"
w
i
n
d
o
w
.
: "jquery", jQuery: "jquery", "window.jQuery": "jquery", "window.
:"jquery",jQuery:"jquery","window.jQuery":"jquery","window.": “jquery”,
Popper: [“popper.js”, “default”]
})
]
}
};
复制代码
⑥ Bootstrap
安装
npm install bootstrap
配置:main.js
// Bootstrap 配置
import ‘bootstrap’
import ‘bootstrap/dist/css/bootstrap.min.css’
⑦ 配置全局自定义设置
在src/assets/js下创建settings.js,输入如下代码
export default {
base_url: ‘http://127.0.0.1:8000’
}
https://github.com/users/fghdfghdf245/projects/1
https://github.com/users/fghdfghdf245/projects/2
https://github.com/users/fghdfghdf245/projects/3
https://github.com/users/fghdfghdf245/projects/4
https://github.com/users/fghdfghdf245/projects/5
https://github.com/users/fghdfghdf245/projects/6
https://github.com/users/fghdfghdf245/projects/7
https://github.com/users/fghdfghdf245/projects/8
https://github.com/users/fghdfghdf245/projects/9
https://github.com/users/fghdfghdf245/projects/10
https://github.com/users/fghdfghdf245/projects/11
https://github.com/users/fghdfghdf245/projects/12
https://github.com/users/fghdfghdf245/projects/13
https://github.com/users/fghdfghdf245/projects/14
https://github.com/users/fghdfghdf245/projects/15
https://github.com/users/fghdfghdf245/projects/16
https://github.com/users/fghdfghdf245/projects/17
https://github.com/users/fghdfghdf245/projects/18
https://github.com/users/fghdfghdf245/projects/19
https://github.com/users/fghdfghdf245/projects/20
https://github.com/users/fghdfghdf245/projects/21
https://github.com/users/fghdfghdf245/projects/22
https://github.com/users/fghdfghdf245/projects/23
https://github.com/users/fghdfghdf245/projects/24
https://github.com/users/fghdfghdf245/projects/25
https://github.com/users/fghdfghdf245/projects/26
https://github.com/users/fghdfghdf245/projects/27
https://github.com/users/fghdfghdf245/projects/28
https://github.com/users/fghdfghdf245/projects/29
https://github.com/users/fghdfghdf245/projects/30
https://github.com/users/fghdfghdf245/projects/31
https://github.com/users/fghdfghdf245/projects/32
https://github.com/users/fghdfghdf245/projects/33
https://github.com/users/fghdfghdf245/projects/34
https://github.com/users/fghdfghdf245/projects/35
https://github.com/users/fghdfghdf245/projects/36
https://github.com/users/fghdfghdf245/projects/37
https://github.com/users/fghdfghdf245/projects/38
https://github.com/users/fghdfghdf245/projects/39
https://github.com/users/fghdfghdf245/projects/40
https://github.com/users/fghdfghdf245/projects/41
https://github.com/users/fghdfghdf245/projects/42
https://github.com/users/fghdfghdf245/projects/43
https://github.com/users/fghdfghdf245/projects/44
https://github.com/users/fghdfghdf245/projects/45
https://github.com/users/fghdfghdf245/projects/46
https://github.com/users/fghdfghdf245/projects/47
https://github.com/users/fghdfghdf245/projects/48
https://github.com/users/fghdfghdf245/projects/49
https://github.com/users/fghdfghdf245/projects/50
https://github.com/users/fghdfghdf245/projects/51
https://github.com/users/fghdfghdf245/projects/52
https://github.com/users/fghdfghdf245/projects/53
https://github.com/users/fghdfghdf245/projects/54
https://github.com/users/fghdfghdf245/projects/55
https://github.com/users/fghdfghdf245/projects/56
https://github.com/users/fghdfghdf245/projects/57
https://github.com/users/fghdfghdf245/projects/58
https://github.com/users/fghdfghdf245/projects/59
https://github.com/users/fghdfghdf245/projects/60
https://github.com/users/fghdfghdf245/projects/61
https://github.com/users/fghdfghdf245/projects/62
https://github.com/users/fghdfghdf245/projects/63
https://github.com/users/fghdfghdf245/projects/64
https://github.com/users/fghdfghdf245/projects/65
https://github.com/users/fghdfghdf245/projects/66
https://github.com/users/fghdfghdf245/projects/67
https://github.com/users/fghdfghdf245/projects/68
https://github.com/users/fghdfghdf245/projects/69
https://github.com/users/fghdfghdf245/projects/70
https://github.com/users/fghdfghdf245/projects/71
https://github.com/users/fghdfghdf245/projects/72
https://github.com/users/fghdfghdf245/projects/73
https://github.com/users/fghdfghdf245/projects/74
https://github.com/users/fghdfghdf245/projects/75
https://github.com/users/fghdfghdf245/projects/76
https://github.com/users/fghdfghdf245/projects/77
https://github.com/users/fghdfghdf245/projects/78
https://github.com/users/fghdfghdf245/projects/79
https://github.com/users/fghdfghdf245/projects/80
https://github.com/users/fghdfghdf245/projects/81
https://github.com/users/fghdfghdf245/projects/82
https://github.com/users/fghdfghdf245/projects/83
https://github.com/users/fghdfghdf245/projects/84
https://github.com/users/fghdfghdf245/projects/85
https://github.com/users/fghdfghdf245/projects/86
https://github.com/users/fghdfghdf245/projects/87
https://github.com/users/fghdfghdf245/projects/88
https://github.com/users/fghdfghdf245/projects/89
https://github.com/users/fghdfghdf245/projects/90
https://github.com/users/fghdfghdf245/projects/91
https://github.com/users/fghdfghdf245/projects/92
https://github.com/users/fghdfghdf245/projects/93
https://github.com/users/fghdfghdf245/projects/94
https://github.com/users/fghdfghdf245/projects/95
https://github.com/users/fghdfghdf245/projects/96
https://github.com/users/fghdfghdf245/projects/97
https://github.com/users/fghdfghdf245/projects/98
https://github.com/users/fghdfghdf245/projects/99
https://github.com/users/fghdfghdf245/projects/100
https://github.com/users/fghdfghdf245/projects/101
https://github.com/users/fghdfghdf245/projects/102
https://github.com/users/fghdfghdf245/projects/103
https://github.com/users/fghdfghdf245/projects/104
https://github.com/users/fghdfghdf245/projects/105
https://github.com/users/fghdfghdf245/projects/106
https://github.com/users/fghdfghdf245/projects/107
https://github.com/users/fghdfghdf245/projects/108
https://github.com/users/fghdfghdf245/projects/109
https://github.com/users/fghdfghdf245/projects/110
https://github.com/users/fghdfghdf245/projects/111
https://github.com/users/fghdfghdf245/projects/112
https://github.com/users/fghdfghdf245/projects/113
https://github.com/users/fghdfghdf245/projects/114
https://github.com/users/fghdfghdf245/projects/115
https://github.com/users/fghdfghdf245/projects/116
https://github.com/users/fghdfghdf245/projects/117
https://github.com/users/fghdfghdf245/projects/118
https://github.com/users/fghdfghdf245/projects/119
https://github.com/users/fghdfghdf245/projects/120
https://github.com/users/fghdfghdf245/projects/121
https://github.com/users/fghdfghdf245/projects/122
https://github.com/users/fghdfghdf245/projects/123
https://github.com/users/fghdfghdf245/projects/124
https://github.com/users/fghdfghdf245/projects/125
https://github.com/users/fghdfghdf245/projects/126
https://github.com/users/fghdfghdf245/projects/127
https://github.com/users/fghdfghdf245/projects/128
https://github.com/users/fghdfghdf245/projects/129
https://github.com/users/fghdfghdf245/projects/130
https://github.com/users/fghdfghdf245/projects/131
https://github.com/users/fghdfghdf245/projects/132
https://github.com/users/fghdfghdf245/projects/133
https://github.com/users/fghdfghdf245/projects/134
https://github.com/users/fghdfghdf245/projects/135
https://github.com/users/fghdfghdf245/projects/136
https://github.com/users/fghdfghdf245/projects/137
https://github.com/users/fghdfghdf245/projects/138
https://github.com/users/fghdfghdf245/projects/139
https://github.com/users/fghdfghdf245/projects/140
https://github.com/users/fghdfghdf245/projects/141
https://github.com/users/fghdfghdf245/projects/142
https://github.com/users/fghdfghdf245/projects/143
https://github.com/users/fghdfghdf245/projects/144
https://github.com/users/fghdfghdf245/projects/145
https://github.com/users/fghdfghdf245/projects/146
https://github.com/users/fghdfghdf245/projects/147
https://github.com/users/fghdfghdf245/projects/148
https://github.com/users/fghdfghdf245/projects/149
https://github.com/users/fghdfghdf245/projects/150
https://github.com/users/fghdfghdf245/projects/151
https://github.com/users/fghdfghdf245/projects/152
https://github.com/users/fghdfghdf245/projects/153
https://github.com/users/fghdfghdf245/projects/154
https://github.com/users/fghdfghdf245/projects/155
https://github.com/users/fghdfghdf245/projects/156
https://github.com/users/fghdfghdf245/projects/157
https://github.com/users/fghdfghdf245/projects/158
https://github.com/users/fghdfghdf245/projects/159
https://github.com/users/fghdfghdf245/projects/160
https://github.com/users/fghdfghdf245/projects/161
https://github.com/users/fghdfghdf245/projects/162
https://github.com/users/fghdfghdf245/projects/163
https://github.com/users/fghdfghdf245/projects/164
https://github.com/users/fghdfghdf245/projects/165
https://github.com/users/fghdfghdf245/projects/166
https://github.com/users/fghdfghdf245/projects/167
https://github.com/users/fghdfghdf245/projects/168
https://github.com/users/fghdfghdf245/projects/169
https://github.com/users/fghdfghdf245/projects/170
https://github.com/users/fghdfghdf245/projects/171
https://github.com/users/fghdfghdf245/projects/172
https://github.com/users/fghdfghdf245/projects/173
https://github.com/users/fghdfghdf245/projects/174
https://github.com/users/fghdfghdf245/projects/175
https://github.com/users/fghdfghdf245/projects/176
https://github.com/users/fghdfghdf245/projects/177
https://github.com/users/fghdfghdf245/projects/178
https://github.com/users/fghdfghdf245/projects/179
https://github.com/users/fghdfghdf245/projects/180
https://github.com/users/fghdfghdf245/projects/181
https://github.com/users/fghdfghdf245/projects/182
https://github.com/users/fghdfghdf245/projects/183
https://github.com/users/fghdfghdf245/projects/184
https://github.com/users/fghdfghdf245/projects/185
https://github.com/users/fghdfghdf245/projects/186
https://github.com/users/fghdfghdf245/projects/187
https://github.com/users/fghdfghdf245/projects/188
https://github.com/users/fghdfghdf245/projects/189
https://github.com/users/fghdfghdf245/projects/190
https://github.com/users/fghdfghdf245/projects/191
https://github.com/users/fghdfghdf245/projects/192
https://github.com/users/fghdfghdf245/projects/193
https://github.com/users/fghdfghdf245/projects/194
https://github.com/users/fghdfghdf245/projects/195
https://github.com/users/fghdfghdf245/projects/196
https://github.com/users/fghdfghdf245/projects/197
https://github.com/users/fghdfghdf245/projects/198
https://github.com/users/fghdfghdf245/projects/199
https://github.com/users/fghdfghdf245/projects/200
https://github.com/users/fghdfghdf245/projects/201
https://github.com/users/fghdfghdf245/projects/202
https://github.com/users/fghdfghdf245/projects/203
https://github.com/users/fghdfghdf245/projects/204
https://github.com/users/fghdfghdf245/projects/205
https://github.com/users/fghdfghdf245/projects/206
https://github.com/users/fghdfghdf245/projects/207
https://github.com/users/fghdfghdf245/projects/208
https://github.com/users/fghdfghdf245/projects/209
https://github.com/users/fghdfghdf245/projects/210
https://github.com/users/fghdfghdf245/projects/211
https://github.com/users/fghdfghdf245/projects/212
https://github.com/users/fghdfghdf245/projects/213
https://github.com/users/fghdfghdf245/projects/214
https://github.com/users/fghdfghdf245/projects/215
https://github.com/users/fghdfghdf245/projects/216
https://github.com/users/fghdfghdf245/projects/217
https://github.com/users/fghdfghdf245/projects/218
https://github.com/users/fghdfghdf245/projects/219
https://github.com/users/fghdfghdf245/projects/220
https://github.com/users/fghdfghdf245/projects/221
https://github.com/users/fghdfghdf245/projects/222
https://github.com/users/fghdfghdf245/projects/223
https://github.com/users/fghdfghdf245/projects/224
https://github.com/users/fghdfghdf245/projects/225
https://github.com/users/fghdfghdf245/projects/226
https://github.com/users/fghdfghdf245/projects/227
https://github.com/users/fghdfghdf245/projects/228
https://github.com/users/fghdfghdf245/projects/229
https://github.com/users/fghdfghdf245/projects/230
https://github.com/users/fghdfghdf245/projects/231
https://github.com/users/fghdfghdf245/projects/232
https://github.com/users/fghdfghdf245/projects/233
https://github.com/users/fghdfghdf245/projects/234
https://github.com/users/fghdfghdf245/projects/235
https://github.com/users/fghdfghdf245/projects/236
https://github.com/users/fghdfghdf245/projects/237
https://github.com/users/fghdfghdf245/projects/238
https://github.com/users/fghdfghdf245/projects/239
https://github.com/users/fghdfghdf245/projects/240
https://github.com/users/fghdfghdf245/projects/241
https://github.com/users/fghdfghdf245/projects/242
https://github.com/users/fghdfghdf245/projects/243
https://github.com/users/fghdfghdf245/projects/244
https://github.com/users/fghdfghdf245/projects/245
https://github.com/users/fghdfghdf245/projects/246
https://github.com/users/fghdfghdf245/projects/247
https://github.com/users/fghdfghdf245/projects/248
https://github.com/users/fghdfghdf245/projects/249
https://github.com/users/fghdfghdf245/projects/250
https://github.com/users/fghdfghdf245/projects/251
https://github.com/users/fghdfghdf245/projects/252
https://github.com/users/fghdfghdf245/projects/253
https://github.com/users/fghdfghdf245/projects/254
https://github.com/users/fghdfghdf245/projects/255
https://github.com/users/fghdfghdf245/projects/256
https://github.com/users/fghdfghdf245/projects/257
https://github.com/users/fghdfghdf245/projects/258
https://github.com/users/fghdfghdf245/projects/259
https://github.com/users/fghdfghdf245/projects/260
https://github.com/users/fghdfghdf245/projects/261
https://github.com/users/fghdfghdf245/projects/262
https://github.com/users/fghdfghdf245/projects/263
https://github.com/users/fghdfghdf245/projects/264
https://github.com/users/fghdfghdf245/projects/265
https://github.com/users/fghdfghdf245/projects/266
https://github.com/users/fghdfghdf245/projects/267
https://github.com/users/fghdfghdf245/projects/268
https://github.com/users/fghdfghdf245/projects/269
https://github.com/users/fghdfghdf245/projects/270
https://github.com/users/fghdfghdf245/projects/271
https://github.com/users/fghdfghdf245/projects/272
https://github.com/users/fghdfghdf245/projects/273
https://github.com/users/fghdfghdf245/projects/274
https://github.com/users/fghdfghdf245/projects/275
https://github.com/users/fghdfghdf245/projects/276
https://github.com/users/fghdfghdf245/projects/277
https://github.com/users/fghdfghdf245/projects/278
https://github.com/users/fghdfghdf245/projects/279
https://github.com/users/fghdfghdf245/projects/280
https://github.com/users/fghdfghdf245/projects/281
https://github.com/users/fghdfghdf245/projects/282
https://github.com/users/fghdfghdf245/projects/283
https://github.com/users/fghdfghdf245/projects/284
https://github.com/users/fghdfghdf245/projects/285
https://github.com/users/fghdfghdf245/projects/286
https://github.com/users/fghdfghdf245/projects/287
https://github.com/users/fghdfghdf245/projects/288
https://github.com/users/fghdfghdf245/projects/289
https://github.com/users/fghdfghdf245/projects/290
https://github.com/users/fghdfghdf245/projects/291
https://github.com/users/fghdfghdf245/projects/292
https://github.com/users/fghdfghdf245/projects/293
https://github.com/users/fghdfghdf245/projects/294
https://github.com/users/fghdfghdf245/projects/295
https://github.com/users/fghdfghdf245/projects/296
https://github.com/users/fghdfghdf245/projects/297
https://github.com/users/fghdfghdf245/projects/298
https://github.com/users/fghdfghdf245/projects/299
https://github.com/users/fghdfghdf245/projects/300
https://github.com/users/fghdfghdf245/projects/301
https://github.com/users/fghdfghdf245/projects/302
https://github.com/users/fghdfghdf245/projects/303
https://github.com/users/fghdfghdf245/projects/304
https://github.com/users/fghdfghdf245/projects/305
https://github.com/users/fghdfghdf245/projects/306
https://github.com/users/fghdfghdf245/projects/307
https://github.com/users/fghdfghdf245/projects/308
https://github.com/users/fghdfghdf245/projects/309
https://github.com/users/fghdfghdf245/projects/310
https://github.com/users/fghdfghdf245/projects/311
https://github.com/users/fghdfghdf245/projects/312
https://github.com/users/fghdfghdf245/projects/313
https://github.com/users/fghdfghdf245/projects/314
https://github.com/users/fghdfghdf245/projects/315
https://github.com/users/fghdfghdf245/projects/316
https://github.com/users/fghdfghdf245/projects/317
https://github.com/users/fghdfghdf245/projects/318
https://github.com/users/fghdfghdf245/projects/319
https://github.com/users/fghdfghdf245/projects/320
https://github.com/users/fghdfghdf245/projects/321
https://github.com/users/fghdfghdf245/projects/322
https://github.com/users/fghdfghdf245/projects/323
https://github.com/users/fghdfghdf245/projects/324
https://github.com/users/fghdfghdf245/projects/325
https://github.com/users/fghdfghdf245/projects/326
https://github.com/users/fghdfghdf245/projects/327
https://github.com/users/fghdfghdf245/projects/328
https://github.com/users/fghdfghdf245/projects/329
https://github.com/users/fghdfghdf245/projects/330
https://github.com/users/fghdfghdf245/projects/331
https://github.com/users/fghdfghdf245/projects/332
https://github.com/users/fghdfghdf245/projects/333
https://github.com/users/fghdfghdf245/projects/334
https://github.com/users/fghdfghdf245/projects/335
https://github.com/users/fghdfghdf245/projects/336