1.vue-cli 做用html
vue-cli做为vue的脚手架,能够帮助咱们在实际开发中自动生成vue.js的模板工程。vue
2.vue-cli 使用webpack
a. 安装全局vue-clinginx
b.初始化,生成项目模板(my_project是项目名,本身随意) npm install vue-cli -g
vue init webpack my_project
选项:
c.进入生成的项目文件夹
d.初始化,安装依赖 cd my_project
npm install
e.运行
npm run dev
项目目录:
1.index.html ---首页入口文件web
(其中 id 为 app 的 div 是页面容器,其中的 router-view 会由 vue-router 去渲染组件,讲结果挂载到这个 div 上。)vue-router
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue Router Demo</title> </head> <body> <div id="app"> <router-view></router-view> </div> <script src="dist/bundle.js"></script> </body> </html>
2.main.js ----核心文件vue-cli
此处的 el:'#app', 表示的是index中的那个 <div id="app"></div>, 它要被 App这个组件 components: { App } 的模板 template: '<App/>'替换。docker
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import router from './router' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: { App } })
3.App.vue ----项目入口文件npm
App这个组件 components: { App } 的模板 template: '<App/>' 的具体内容。其中的 router-view 会由 vue-router 去渲染组件,讲结果挂载到这个 div 上api
<template> <div id="app"> <img src="./assets/logo.png"> <router-view></router-view> </div> </template> <script> export default { name: 'app' } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
4.router/index.js -----路由与组件
import Vue from 'vue' import Router from 'vue-router' import Hello from '@/components/Hello' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'Hello', component: Hello } ] })