vue - 指令系统
指令系统:
所谓指令系统,大家可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了。
在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上。
1. v-if v-else-if v-else
2. v-show
一般来说,
v-if
有更高的切换开销,而v-show
有更高的初始渲染开销。因此,如果需要非常频繁地切换,则使用v-show
较好;如果在运行时条件很少改变,则使用v-if
较好。
3. v-bind 简写为 :
4. v-on 简写为 :@
5. v-for
6. v-html
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{padding: 0; margin: 0;}
.box{width: 100px;height: 100px;background-color: red;}
.box2{background-color: green;}
.lunbo ul{width: 180px; overflow: hidden; list-style: none;}
.lunbo ul li{float: left; width: 30px; height: 30px; background-color: purple; margin-left: 5px; line-height: 30px; text-align: center;
color: white;}
</style>
</head>
<body> <div id="app">
<!-- 插值语法 react{} angular{{}} {% %} <%= %> -->
<!-- 除了 if else -->
<h3>{{123}}</h3>
<h3>{{msg}}</h3>
<h3>{{1>2?"真的":"假的"}}</h3> <div v-if = 'show'>哈哈哈哈</div> <!-- <button v-on:click = 'clickHandler' >切换</button> --> <button @click = 'clickHandler' >切换</button> <div v-if="Math.random() > 0.5">
Now you see me
</div>
<div v-else>
Now you don't
</div> <h3 v-show='iShow' v-bind:title="title">我是一个三级标题</h3> <img v-bind:src="imgSrc" :title="time" width="100px;height100px;"> <!--
v-bind: 简便写法 :
v-on:click 简便写法 @click
--> <div class="box" :class="{box2:isGreen,box3:isYellow}"></div> <button @click='changeColor'>切换颜色</button> <button @click='count+=1'>加{{count}}</button> <!--
声明式的指令
命令式的
--> <div class='lunbo'>
<img :src="currentSrc" @mouseenter='closeTimer' @mouseleave='openTimer' width="100" height="100">
<ul>
<li v-for = "(item,index) in imgArr" @click='currentHandler(item)'>{{index+1}}</li>
</ul>
</div> <button @click='nextImg'>下一张</button> <div v-html="str"></div>
</div> <script type="text/javascript" src="./vue.js"></script> <script type="text/javascript"> // vue的实例化对象 // MVVM model view viewmodel // MTV model template view // 指令系统 v-* // 核心思想概念: 数据驱动视图 ,双向的数据绑定 var app = new Vue({
el: "#app",
data: {
msg:"今天学习vue",
msg2:"今天学习vue2",
show:false,
iShow:true,
title:"哈哈哈",
imgSrc:"./5.jpg",
time: `页面加载于${new Date().toLocaleString()}`,
isGreen:true,
isYellow:true,
count:0,
imgArr:[
{id:1,src:'./1.jpg'},
{id:2,src:'./2.jpg'},
{id:3,src:'./3.jpg'},
{id:4,src:'./4.jpg'}
],
currentSrc:"./1.jpg",
currntIndex:0,
timer:null,
str:"<p>嘿嘿嘿</p>"
},
created(){
// 加载dom之前
// 开启定时器
// 获取cookie session 提前获取出来
this.timer = setInterval(this.nextImg,2000)
},
methods:{
clickHandler(){
this.show = !this.show;
},
changeColor(){
this.isGreen = !this.isGreen
},
currentHandler(item){
this.currentSrc = item.src
},
nextImg(){
if (this.currntIndex == this.imgArr.length-1){
this.currntIndex=-1
}
this.currntIndex++
this.currentSrc = this.imgArr[this.currntIndex].src
},
closeTimer(){
clearInterval(this.timer)
},
openTimer(){
this.timer = setInterval(this.nextImg,2000)
} } }) // 直接取操作dom 但是不介意这样用!,应该使用vue对dom操作
console.log(app)
console.log(app.$el)
console.log(app.$data.msg)
console.log(app.msg)
console.log(app.msg2) </script> </body>
</html> <!-- 找相关资料
开发者网络 上一张; -->
vue - 指令系统的更多相关文章
- day67:Vue:es6基本语法&vue.js基本使用&vue指令系统
目录 Vue前戏:es6的基本语法 1.es6中的let特点 1.1.局部作用域 1.2.不存在变量提升 1.3.不能重复声明 1.4.let声明的全局变量不从属于window对象,var声明的全局变 ...
- vue——指令系统
指令系统,可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上. 在vue中提供了一套为数 ...
- vue 指令系统的使用
所谓指令系统,大家可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上. OK,接下来我们 ...
- vue指令系统
一.vue基础 使用vue需在官网上先下载vue.js,网址:https://cn.vuejs.org/v2/guide/installation.html.然后: 在project中引入vue.js ...
- 3. Vue - 指令系统
一.vue指令 (1) v-if // 条件判断 如果条件成立就在页面上生成一个标签并显示出来 (2) v-show //DOM中都存在只是显示与否 (3) v-for //注意 v-bind:key ...
- python全栈开发之路
一.Python基础 python简介 python数据类型(数字\字符串\列表) python数据类型(元组\字典) python数据类型(集合) python占位符%s,%d,%r,%f prin ...
- vue-learning:3-template-{{}}-and-v-html
插值{{ }} 和 v-html 本节开始,我们按如下顺序学习vue模板API-指令.点击各部分的DEMO可在线查看代码 输出字符串文本内容的插值:{{}} 输出HMTL元素作为内容的指令:v-htm ...
- vue-learning:2 - template - directive
指令 directive 在上一节我们知道,VUE的template模板通过VUE指令API实现与页面的视图层联系.所以本节将聚集在实现视图层交互的VUE指令系统directive的基础使用. 我们先 ...
- Vue的指令系统、计算属性和表单输入绑定
指令系统 指令 (Directives) 是带有 v- 前缀的特殊特性.指令特性的值预期是单个 JavaScript 表达式 (v-for 是例外情况,稍后我们再讨论).指令的职责是,当表达式的值改变 ...
随机推荐
- jfinal框架的初级学习
1.同strust2,使用jfinal框架首先需要在web.xml配置自己的过滤器(com.jfinal.core.JFinalFilter),并初始化JFinalConfig类. <filte ...
- PHP利用memcache缓存技术提高响应速度
PHP下memcache模块是一个高效的守护进程,提供用于内存缓存的过程式程序和面向对象的方便的接口,特别是对于设计动态web程序时减少对数据库的访问.memcache也提供用于通信对话(sessio ...
- iOS 自动编译脚本
#!/bin/sh #项目路径 PROJECT_DIR="/Users/mac/Desktop/_housemart" #临时项目 PROJECT_TEMP_DIR="/ ...
- linux nfs
linux(十四)之linux NFS服务管理 学到这里差不多就结束了linux的基础学习了,其实linux的内容并不难,我们要经常的反复的去操作它,多多和它去联络感情才能很好的掌握这个linux. ...
- make的自动变量和预定义变量
make的自动变量 $@ 规则目标的文件名.如果目标是档案文件的一个成员,"$@"就是档案文件的名称 $% 当目标是档案文件的一个成员时,"$%"是该成员的名称 ...
- Effective C++ Item 14 Think carefully about copying behavior in resource-managing classe
In C++, the only code that guaranteed to be executed after an exception is thrown are the destructor ...
- THINKPHP include 标签动态加载文件
有时候需要在框架中动态的加载一些文件,文件名不确定,有控制器获取得到,想在模板中使用变量的形式进行加载,本以为这样写可以 结果不行 <include file="User/{$my_t ...
- 服务器允许js跨域
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Methods:POST,GET'); header('Ac ...
- nutch 存储到数据库
就像我们知道的一样,nutch是一个架构在lucene之上的网络爬虫+搜索引擎. 是由lucene的作者在lucene基础之上开发,并整合了hadoop,实现在分布式云计算,使用google标准的HF ...
- PyQt4 菜单栏 + 工具栏 + 状态栏 + 中心部件 生成一个文本编辑部件示例
我们将创建一个菜单栏.一个工具栏.一个状态栏和一个中心部件. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from PyQt4 import ...