1:P61(值绑定)

<input type="checkbox" v-model="toggle" :true-value="a" :false-value="b"/>
<span>{{toggle}}</span>
</div>

对应的js

var example = new Vue({
el:'#example',
data: {
toggle: '',
a:'aaa',
b:'bbb'
}
});

效果选中状态:

2:P74 过滤器 filter语法

js代码:

var example = new Vue({
el:'#example',
data: {
message: 'hello'
},
filters:{
reserve:function(value,begin,end){
return value+begin+end;
}
}
});

相应的html

<span>{{ message | reserve('arg1', 'arg2') }}</span>

显示效果为: helloarg1arg2

但是按照书中的例子出不来效果;P76双向过滤器出不来该效果:

<div id="example">
<p>{{message}}</p>
<input type="text" v-model="message | filterExample"/>
</div>

js

Vue.filter('filterExample',{
read:function(val){
return 'read'+val;
},
write: function(newval,oldval){
return oldval+'write';
} });
var example = new Vue({
el:'#example',
data: {
message: 'hello'
} });

P96 methods配置:html:

<div id="example">
<p>{{message}}</p>
<button class="mybox" v-on:click="green"></button>
</div>

对应的js代码:

var example = new Vue({
el:'#example',
data: {
message: 'hello'
},
methods:{
green:function(event){//注意这里的event和target的使用方法
$(event.target).css('background','green');//使用$()形成 jquery对象
}
} });

P98 prevent阻止默认事件,stop阻止冒泡事件:

<div id="example">
<a v-on:click.stop.prevent="doThat" href="http://www.baidu.com">链接</a>
</div>

js代码:

var example = new Vue({
el:'#example',
data: {
message: 'hello'
},
methods:{
green:function(event){
$(event.target).css('background','green');
},
doThat:function(){
alert('nihao');
}
}
});

效果:点击链接后不会跳转,而是执行doThat函数,出现alert警告。

P108 要注意组件的名称:

var ddComponent=Vue.extend({
template:'<p>this is a template</p>'
});
Vue.component('didi-component',ddComponent);
var example = new Vue({
el:'#example',
data: {
message: 'hello'
}
});

这里组件didi-component的名字还可以写成component,但注意不要写成didiComponent的驼峰式写法

相应的html为:

<div id="example">
<didi-component></didi-component>
</div>

vue.js权威指南----代码解释实例的更多相关文章

  1. 【vue.js权威指南】读书笔记(第一章)

    最近在读新书<vue.js权威指南>,一边读,一边把笔记整理下来,方便自己以后温故知新,也希望能把自己的读书心得分享给大家. [第1章:遇见vue.js] vue.js是什么? vue.j ...

  2. 【vue.js权威指南】读书笔记(第二章)

    [第2章:数据绑定] 何为数据绑定?答曰:数据绑定就是将数据和视图相关联,当数据发生变化的时候,可以自动的来更新视图. 数据绑定的语法主要分为以下几个部分: 文本插值:文本插值可以说是最基本的形式了. ...

  3. vue.js权威指南 PDF

    链接:https://pan.baidu.com/s/1c2ItN6S 密码:ya8r

  4. 《JS权威指南学习总结--1.1语言核心》

    1.1语言核心 --本节主要介绍<js权威指南>基础部分各章讲解内容和一些简单的示例 本小节内容: 一.第二章讲解js注释.分号和Unicode,第三章主要讲解js变量和赋值 简单示例: ...

  5. 《JS权威指南学习总结》

    JS权威指南学习总结:http://www.cnblogs.com/ahthw/category/652668.html

  6. 《JS权威指南学习总结--开始简介》

    本书共分成了四大部分: 1.JS语言核心 2.客户端JS 3.JS核心参考 4.客户端JS核心参考 其中 <JS权威指南学习总结--1.1语法核心> 是:第一部分JS语言核心 各章节重点 ...

  7. Vue.js 入门指南

    1.Vue.js是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的 渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计.Vue 的核心库只关注 ...

  8. vue.js 贡献指南(翻译)

    Vue.js Contributing Guide vue 2.x 嗨! 我很高兴你有兴趣为Vue.js做贡献. 在提交您的贡献之前,请务必花点时间阅读以下指南. 行为守则 问题报告指南 PR指南 开 ...

  9. Vue.js 入门指南之“前传”(含sublime text 3 配置)

    题记:关注Vue.js 很久了,但就是没有动手写过一行代码,今天准备入手,却发现自己比菜鸟还菜,于是四方寻找大牛指点,才终于找到了入门的“入门”,就算是“入门指南”的“前传”吧.此文献给跟我一样“白痴 ...

随机推荐

  1. 17初识select

    多路复用 select 同时监控多个文件描述符的输入输出 <sys/types.h> <sys/times.h> <sys/select.h> int select ...

  2. uva11732 Trie转化

    有40001 个单词每个单词长度不超过1000,每个两个单词之间都要比较求要比较次数 int strcmp(char *s,char *t){ int i; for(i = 0; s[i]==t[i] ...

  3. 【转载】open-falcon部署

    运维监控系统之Open-Falcon   一.Open-Falcon介绍 1.监控系统,可以从运营级别(基本配置即可),以及应用级别(二次开发,通过端口进行日志上报),对服务器.操作系统.中间件.应用 ...

  4. 服务器负载、CPU性能判断

    说在前面: 在linux操作系统中,我们一般查看系统的cpu负载情况常用的命令可以是uptime,top,还有vmstat等这些个都是可以有的.每个工具所提供的信息各不相同, 我这里要讨论的仅说cpu ...

  5. springcloud15---zuul-fallback

    package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframew ...

  6. iptables命令、规则、参数详解

    表    (table)包含4个表:4个表的优先级由高到低:raw-->mangle-->nat-->filterraw---RAW表只使用在PREROUTING链和OUTPUT链上 ...

  7. nw.js node-webkit系列(17)怎样打包和分发你的应用

    原文链接:http://blog.csdn.net/zeping891103/article/details/50790180

  8. 20145122《Java程序设计》第一周学习总结

    这周的JAVA学习开始了. 首先我了解JVM.JRE与JDK的区别与联系.JDK : (Java开发工具包).JDK是整个Java的核心,包括了Java运行环境JRE.Java工具和Java基础类库等 ...

  9. linux下如何kill tty终端

    答:一共有两个步骤,如下: 1.列出打开的终端 who 2.kill需要kill的tty终端 pkill -kill -t pts/2

  10. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations 矩阵快速幂优化dp

    D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes inpu ...