VUE (View Layer)
1. Knowledge preparation
构建用户界面
渐进式框架
可自底向上逐层应用
简洁的模板语法来声明式地将数据渲染进 DOM 的系统
npm 是 JavaScript 世界的包管理工具
npm 是是 Node.js 平台的默认包管理工具
npm集成在node中
通过 npm 可以安装、共享、分发代码、管理项目依赖关系
Second, the installation process
1. Install node.js
- Browser download node: http://nodejs.cn/download/
- Install node software: node-v16.14.2-x64.msi
- Test command: node -v
- npm manager test: npm -v
2, npm and cnpm installation - Node Package Manager
- 安装cnpm:npm install -g cnpm --registry=http://registry.npm.taobao.org
- Add cnpm Taobao mirror: npm install -g cnpm --registry=https://registry.npm.taobao.org
- Re-update the npm mirror: npm i npm -g
- Upgrade npm: cnpm install npm -g
- Upgrade and install cnpm: npm install cnpm -g
- Latest stable version: cnpm install vue
3. Scaffolding vue.cli installation - Vue CLI = Vue + js plugin
- Install the vue-cli scaffolding build tool: npm install -g vue-cli
- Install vue-cli globally: npm install --global vue-cli
- Reinstall the @vue.cli scaffold: cnpm i @vue/cli -g
- Check: vue -V
3, webpack static module bundler (module bundler)
- webpack version: webpack -v
- Install globally: npm install webpack webpack-cli –g
- To remove a package: npm uninstall <package name>
- To remove a package: npm uninstall -g <package name>
- Update package: npm outdated -g --depth=0
- Taobao mirror detection update: cnpm outdated -g --depth=0
- Update packages: npm update -g <package name>
- Quick build: npm init --yes
4. Install vue3.0 (with UI) - Vue CLI = Vue + js plugin
- Install Vue: npm install -g @vue/cli
- Install new scaffolding: cnpm i -g @vue/cli
- View commands: vue -h
- Initialize scaffolding: npm install -g @vue/cli-init
5. Vue use
- VUE interface: vue ui
- Create a project: vue init webpack vue_test (project folder name)
- Automatically create projects: vue create project/vue ui
6. Installation dependencies
- Enter the specific project folder: cd vue_test (project name)
- npm install, press enter, wait for a while
3. How to use
4. Grammar Examples
<div id="app">
{
{ message }}
</div>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
Fourth, the directory structure
build 项目构建(webpack)相关代码
config 配置目录,包括端口号等。我们初学可以使用默认的。
node_modules npm 加载的项目依赖模块
src 开发目录,基本上要做的事情都在这个目录里。里面包含了几个目录及文件
assets: 放置一些图片,如logo等。
components: 目录里面放了一个组件文件,可以不用。
App.vue: 项目入口文件,我们也可以直接将组件写这里,而不使用 components 目录。
main.js: 项目的核心文件。
static 静态资源目录,如图片、字体等。
test 初始测试目录,可删除
.xxxx文件 这些是一些配置文件,包括语法配置,git配置等。
index.html 首页入口文件,你可以添加一些 meta 信息或统计代码啥的。
package.json 项目配置文件。
README.md 项目的说明文档,markdown 格式
5. VUE components: -g global, @version, scaffolding (code generator)
1. npm (foreign): package manager (similar to MAVEN) written in JavaScript
作用:node包管理器、程序包管理和分发的管理工具
位置:已经集成在NODE.JS中
- Download and install command: npm install jquery
- Specify the version to install: npm install jquery@1
- View the installation path: npm config get prefix
- Set the global installer package directory: npm config set prefix “E:\NpmInstall”
- Set the global cache directory: npm config set cache “E:\NpmInstall\cache”
2. cnpm (domestic): Taobao mirror npm
- Install Taobao mirror: npm install -g cnpm --registry=https://registry.npm.taobao.org
3. webpack (packaging): through CommonJS syntax
作用:前端资源加载/打包工具、多种静态资源 js、css、less 转换成一个静态文件
- Taobao mirror to install Webpack: cnpm install webpack -g
- Create a project directory: mkdir app
- Add runoob1.js to the directory: document.write("It works.");
- Add index.html to the directory: </script type="text/javascript" src="bundle.js" charset="utf-8"></script/>
- webpack command packaging: webpack runoob1.js bundle.js
4. vue-cli: Vue project template (scaffolding code generator) - Vue CLI = Vue + js plugin
作用:快速创建 vue 项目、基于 Vue.js 、降低webpack使用难度
- Install vue-cli globally: npm install --global vue-cli
- View version: vue -V
- Update the global Vue CLI package: npm update -g @vue/cli
- Upgrade the global Vue CLI package: yarn global upgrade --latest @vue/cli
- Create a project: vue create hello-world
- Graphical interface: vue ui