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 是例外情况,稍后我们再讨论).指令的职责是,当表达式的值改变 ...
随机推荐
- UI标签库专题十一:JEECG智能开发平台 DictSelect (数据字典下拉选择框)
1. DictSelect (数据字典下拉选择框) 1.1. 參数 属性名 类型 描写叙述 是否必须 默认值 typeGroupCode string 字典分组编码 是 null field s ...
- par函数fg参数-控制前景色
fg参数用来控制前景色,其实指的就是x轴和y轴的轴线和刻度线的颜色 在R语言中,会根据fg, col 任何一个参数的值,自动的将两个参数的值设置为相同的值,举个例子: par(fg = "r ...
- nginx+tomcat实现负载均衡以及session共享(linux centos7环境)
一.nginx的安装 1.准备三份tomcat tomcat1 设置端口 8080 tomcat2 设置端口 8081 tomcat3 设置端口 8082 2. 下载nginx 3. 解压到/home ...
- jQuery checkbox选中问题之prop与attr注意点分析
$(function () { // 全选 $("#btnCheckAll").bind("click", function () { $(&q ...
- CSS之少用继承,多用组合
下面是一段普通的代码: css: .box{ border:1px solid #ccc; font-size:12px; background:#f1f1f1; padding:10px; } ht ...
- SPP-Net
R-CNN -> SPP-Net -> Fast-RCNN
- 在VS中安装/使用 MVVMLight
一般来说,我喜欢使用NuGet来获取这些东西,比如Newtonsoft.Json.netlog4.MVVMLight 之类的东西.至于NuGet的使用,以后再说吧.为了直接进入正题,我们这里直接使用V ...
- work,i/o最小线程设置
设置work i/o最小线程有两种方式1.通过配置文件设置,影响所有iis部署程序(待验证)2.通过程序代码设置,iis上部署的程序互不影响int minWorker, minIOC; //Get t ...
- spring 事物管理没起到作用
今天在做项目的时候发现配置的spring 事物管理没起到作用.可是配置又是依据官网配置的,不可能会错.最后发现使mysql的问题 普通情况下,mysql会默认提供多种存储引擎,你能够通过以下的查看: ...
- Java精选笔记_IO流(字符输入输出流、字符文件输入输出流、字符流的缓冲区)
字符流 Reader是字符输入流的基类,用于从某个源设备读取字符 Writer是字符输出流,用于向某个目标设备写入字符 字符流操作文件 字符输入流FileReader,通过此流可以从关联的文件中读取一 ...