https://cn.vuejs.org/v2/guide/
nodejs中集成了npm 因此需要安装nodejs,官方地址是https://nodejs.org/en/ 查看当前npm版本
npm --version
6.4.1
sudo npm install -g npm
npm install vue
$ npm install -g vue-cli
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
/usr/local/bin/vue-list -> /usr/local/lib/node_modules/vue-cli/bin/vue-list
/usr/local/bin/vue-init -> /usr/local/lib/node_modules/vue-cli/bin/vue-init
/usr/local/bin/vue -> /usr/local/lib/node_modules/vue-cli/bin/vue
+ vue-cli@2.9.6
added 121 packages from 134 contributors, removed 10 packages, updated 1 package and moved 97 packages in 132.885s
npm install webpack -g
运行
npm run dev
nvm 安装 https://github.com/nvm-sh/nvm/blob/master/README.md
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to ~/.bash_profile or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && . "/usr/local/opt/nvm/etc/bash_completion" # This loads nvm bash_completion
安装Vue.js devtools
cdn 加速地址 https://www.bootcdn.cn/vue/
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
npm uninstall -g vue-cli
npm install -g @vue/cli
vue --version
3.8.2
使用脚手架创建helloworld工程
vue create hello-world
Vue CLI v3.8.2
? Please pick a preset: (Use arrow keys)
❯ default (babel, eslint)
Manually select features
? Successfully created project hello-world.
? Get started with the following commands:
$ cd hello-world
$ npm run serve
cd hello-world
npm run serve
CLI3热部署项目使用的命令是
npm run serve
使用原先CLI2版本创建项目
vue init webpack my-project
$ vue init webpack my-project
? Project name my-project
? Project description A Vue.js project
? Author baxiang <baxiang@roobo.com>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) npm
vue-cli · Generated "my-project".
运行项目
npm run dev
DONE Compiled successfully in 4486ms 12:14:53 PM
I Your application is running here: http://localhost:8080
$ tree -L 2
.
├── App.vue
├── assets
│ └── logo.png
├── components
│ └── HelloWorld.vue
├── main.js
└── router
└── index.js
3 directories, 5 files
在components文件夹下创建HelloVue文件
<template>
<div>
你好 Vue
</div>
</template>
<script>
export default {
name: "HelloVue"
}
</script>
<style scoped>
</style>
在router文件下的index.js增加路由配置
import HelloWorld from '@/components/HelloWorld'
import HelloVue from '@/components/HelloVue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/HelloVue',
name: 'HelloVue',
component: HelloVue
},
]
})
<body>
<div id="app">
<!-- 通过{{}}将data中定义的展示到页面-->
{{msg}}
</div>
<script>
//创建Vue实例,Vue实例管理html代码
let vm = new Vue({
// 通过构造函数参数el属性指定vue实例需要管理的范围,这个el属性的值是一个id
el:'#app',
// 通过data属性保存页面需要用到的数据
data:{
msg:"hello Vue"
}
})
</script>
</body>