Vue
模板语法,条件渲染,列表渲染
vue-router vuex
vue-cli

用到的网站:
https://cn.vuejs.org/v2/guide/
https://cli.vuejs.org/zh/guide/
https://www.bootcdn.cn/

开发环境

1、IDE

  • webstorm http://www.jetbrains.com/webstorm
  • vscode https://code.visualstudio.com/

2、node环境

(1)nvm Node Version Manager
node 多版本管理工具

[1] 安装
https://github.com/nvm-sh/nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

vim ~/.bash_profile
或者全局配置在这个目录下
/etc/profile.d

# nvm配置
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

[2]使用

$ nvm --version  # 0.34.0
nvm --help
nvm ls
nvm ls-remote
nvm install 8.0.0
nvm deactivate  # 卸载时使用$ node --version
v8.0.0

(2) cnpm淘宝镜像
http://npm.taobao.org/

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

(3)chrome插件
vue.js devtools

chrome vue插件下载地址
https://chrome-extension-downloader.com/

(4)vue-cli

$ npm install -g @vue/cli   # 全局安装
$ vue --version

环境检查

$ nvm --version
0.34.0
$ node --version
v8.16.0
$ npm --version
5.0.0
$ vue --version
2.9.6
$ npm ls -g --depth=0

模板语法

1、文件结构
-template
-script
-css

2、插值语法,数据,js表达式
3、指令(指令缩写) @click,v-if, :href

vueCDN: https://www.bootcdn.cn/

代码示例

<html>
<head>
<!-- 可以在head标签中 通过CND引入-->
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
</head><body>
<!-- 模板部分-->
<div id="app"><div>{{message}}</div>          <!--变量替换 hello world! --><div>{{ count + 1 }}</div>      <!--数值运算 2 --><div>{{template}}</div>         <!--原样显示 <div>hello div</div> --><div v-html="template"></div>   <!--标签解析 hello div --><!--属性绑定 3者等效--><div><a href="https://www.baidu.com">百度</a></div><div><a v-bind:href="url">百度</a></div>   <div><a :href="url">百度</a></div><!--事件绑定 2者等效--><div><button v-on:click="add()">count+1</button></div><div><button @click="add()">count+1</button></div>
</div><!--js部分-->
<script>
new Vue({el: "#app",  // 绑定的对象// 数据data: {   message: "hello world!",count: 1,template: "<div>hello div</div>",url: "https://www.baidu.com"},// 方法methods: {add: function() {this.count += 1;}}});
</script>
</body>
</html>

计算属性和侦听属性

软回车(换行不删除):shift+enter

计算属性  computed   数据联动   监听多个属性
侦听器    watch      异步场景   监听一个属性

代码示例


<div id="app"><div>{{message}}</div><div>{{fullMessage }}</div>
</div><script>
var app = new Vue({el: "#app",data: {message: "hello"},// 侦听属性watch: {message: function(newVal, oldVal) {console.log(oldVal + " => " + newVal);}},// 计算属性computed: {fullMessage: function(){return `数据:${this.message}`;}}
});
</script>

渲染

条件渲染: v-if, v-else, v-else-if; v-show
列表渲染: v-for
Class与Style绑定

代码示例


<div id="app"><!-- if 条件判断 --><div v-if="count===0">count的值===0</div><div v-else-if="count > 0">count的值 > 0</div><div v-else>count的值 < 0</div><!-- show 条件判断 --><div v-show="count==5">count的值 == 5</div><!-- 循环渲染 --><div v-for="item in students">{{item.name}} | {{item.age}}</div><!-- 循环渲染和条件渲染结合 --><div v-for="item in students"><div v-if="item.age > 23">{{item.name}}: age>23</div><div v-else>{{item.name}}</div></div><!-- 样式渲染 --><div v-for="item in students"><div v-show="item.age > 23":class="['red', 'gree', {'red': item.age<23}]":style="itemStyle">{{item.name}}</div></div>
</div><script>
var app = new Vue({el: "#app",data: {count: 0,students: [{name: "小仓",age: 23},{name: "小龙",age: 24}],// style属性itemStyle: {color: "red"}}
});
</script>

vue-cli

$ vue create hello-world  # 创建项目
$ npm run server          # 启动项目

1、组件化思想
实现功能模块复用
开发复杂应用

原则:
300行原则
复用原则
业务复杂性原则

2、风格指南
https://cn.vuejs.org/v2/style-guide/

3、Vue-router
配置router.js

4、Vuex
state 状态
mutations 方法集
actions
vuex管理不同组件共用变量,一个组件改变变量,另一个跟着改变。

store.js 定义全局数据和方法

export default new Vuex.Store({// 定义公共的数据state: {count: 0},// 公共的方法mutations: {increase() {this.state.count ++;}},actions: {},
});

info.vue 修改全局变量

<template><div>info <button @click="add()">加一</button></div>
</template><script>
// 导入文件 @相当于src目录
import store from "@/store"export default{name: "Info",store,// 整个生命周期绑定mounted(){window.app = this;},methods: {add: function() {console.error("加一");debugger;// 调用store中的increase方法store.commit("increase");},output: function(){console.log("out put");}}
}
</script>

about.vue调用全局数据

<template><div class="about"><h1>This is an about page</h1><div>{{msg}}</div></div>
</template><script>
import store from "@/store"export default{name: "About",store,data(){return {msg: store.state.count}}
}
</script>

5、调试
console.log()
console.error()
alert() 阻塞
debugger 断点
window对象绑定

6、集成vue

Git工作流

# 拉取仓库
git clone git@hello.git
cd hello
git status
git branch -a   # 本地远程分支
git branch# 添加新文件
touch text.txt
git status
git add .
git commit -m "初次提交"
git remote -v   # origin 远程仓库
git push origin master  # 推送到远程主干分支# 新需求分支
git checkout -b dev
touch test1.txt
git add test1.txt
git commit -m "dev功能开发"
git push origin dev  # 推送到dev分支# 合并分支到master上
git checkout master
git merge dev
git push origin master  # 提交到远程master分支
git branch -d dev       # 删除本地dev分支
git push origin :dev    # 删除远程dev分支# 回退版本
git reset --hard head^   # 回退到上一版本git log
git reflog
git reset --hard HEAD@{1}

快速原型开发

npm install -g @vue/cli-service-globalvue serve demo.vue

demo.vue

<template><div><ul><li v-for="(item, index) in list":class="{'active': index===currentIndex}":key="index"@click="selectItem(index)">{{item}}</li></ul><button type="button" @click="add()">添加</button><ul><li v-for="(item, index) in target":key="index">{{item}}</li></ul></div>
</template><script>
export default {name: "demo1",data() {return{currentIndex: -1,list: [1, 2, 3, 4],target: []}},methods: {add(){if (this.currentIndex < 0){return}this.target.push(this.list[this.currentIndex]);this.currentIndex = -1;},// 选中的时候selectItem(index) {this.currentIndex = index;}}}
</script><style>
.active{background-color: green;color: white
}
</style>

app应用

vue ui

localStorage
scss方式书写css

打包部署
npm run build

总结

模板语法
风格指南
vue-router、vuex、调试
vue-cli
vue集成
开发工作流

Vue:从单页面到工程化项目相关推荐

  1. vue多单页面多tab_vue-cli3创建多页面项目

    开发了很多个单页面的项目,也开发了很多原生的项目,就是一直没机会开发多页面和单页面混合的项目,于是自己去查了一些资料,用的是vue-cli3脚手架搭建了一个多页面和单页面混合的小demo. 首先,vu ...

  2. Java快速开发平台,JEECG 3.7.5 Vue SPA单页面应用版本发布

    JEECG 3.7.5 Vue SPA单页面应用版本发布 导读            ⊙ Vue+ElementUI SPA单页面应用 ⊙Datagrid标签快速切换BootstrapTable列表风 ...

  3. [vue] SPA单页面的实现方式有哪些?

    [vue] SPA单页面的实现方式有哪些? 1.监听地址栏中hash变化驱动界面变化2.用pushsate记录浏览器的历史,驱动界面发送变化3.直接在界面用普通事件驱动界面变化它们都是遵循同一种原则: ...

  4. list vue 删除后页面渲染_Vue项目中v-for数组删除第n项元素产生渲染错误问题及解决方法...

    项目背景 最近使用Vue(版本2.9)开发一个项目时,要生成表单列表,所以使用了v-for来做循环,循环里的元素(item)是一个子组件.同时每个元素都有删除按钮,点击后删除当前元素. 初始代码如下: ...

  5. vue与单页面 使用Photo Sphere Viewer创建vr 360全景示例代码

    图片资料来源于:http://resource.haorooms.com/uploads/demo/media/3Dqj/index.html  因本人注册账号下载参考之后再到vue项目中,若有侵权请 ...

  6. 为什么说Vue是单页面应用呢?

    相信很多初学Vue的小伙伴都有一个疑惑,为什么使用Vue所制作的网页是单页面的呢?下面我们一起来探讨一下这个问题. 我们都知道Vue的工作就是将我们的数据渲染到页面上.想要在模板上渲染数据,首先就要把 ...

  7. 新手vue构建单页面应用实例

    本人写的小程序,功能还在完善中,欢迎扫一扫提出宝贵意见!           步骤: 1.使用vue-cli创建项目 2.使用vue-router实现单页路由 3.用vuex管理我们的数据流 4.使用 ...

  8. Vue.js进阶【3】纯Vue实现单页面-列表增删改查

    增删改查最能代表一个技术的完备性的,下面就展示Vue的增删改查,为了界面的美观实用了bootstrap 仔细阅读下面的代码,即可领会其意思.不懂的标签和元素百度查一下一查一大堆.很快就可以理解了 运行 ...

  9. vue.js单页面应用实例

    一:npm的安装 由于新版的node.js已经集成了npm的环境,所以只需去官网下载node.js并安装,安装完成后使用cmd检测是否成功. 测试node的版本号:node -v 测试npm的版本号: ...

最新文章

  1. MySQL中的索引详讲
  2. 直流耦合and交流耦合
  3. python 碎片整理 threading模块小计
  4. 【离散数学】实验 编写一个简单的三人表决器
  5. 25-60k/m | 湃道智能招聘
  6. HIT Software Construction Review Notes(0-1 Introduction to the Course)
  7. live555+ffmpeg如何提取关键帧(I帧,P帧,B帧)
  8. DRY(Don't Repeat Yourself )原则
  9. 【物流选址】基于matlab佛洛依德算法求解物流选址问题【含Matlab源码 892期】
  10. Java连接数据库(增删改查)
  11. win7系统无法正常启动
  12. Re:天选2之找不到WLAN网络
  13. 刷IP工具、刷IP软件的原理和工作过程
  14. gitbook:epub电子书制作教程
  15. 27 信息过滤与反垃圾
  16. ISO8583报文(一)
  17. python中的列表是什么意思_python中列表的用法是什么
  18. 评估数据质量的指标总结1
  19. 读书笔记:你在为谁工作
  20. gyp: No Xcode or CLT version detected! 错误提示

热门文章

  1. python32位和64位有什么区别_python32位和64位的区别是什么
  2. 深度解析用户画像标签体系构建方法
  3. C语言 经典例题 无重复三位数
  4. 音视频学习之时间戳相关整理(时间基tbr,tbn,tbc)
  5. 22 信息系统安全管理
  6. Ubuntu16.04+CUDA8.0+GTX960M安装
  7. 【转】windows安装jira
  8. 高分屏笔记本显示模糊解决方法
  9. 人工智能数据标注平台推荐
  10. 苹果收取30%过路费_你是顶是踩?