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. 解决 failed to push some refs to 'git@github.com:zle1992/head-first-java' hint: Updates were rejected because the tip of your curr

    问题描述: 寒假之前用实验室电脑push到github 上head first java 的程序,寒假回家后,想用自己的笔记本继续编,继续push . 我先从github下载zip到本地,然后 解压后 ...

  2. WdatePicker显示乱码

    1.修改zh-cn.js内容: var $lang={ errAlertMsg: "不合法的日期格式或者日期超出限定范围,需要撤销吗?", aWeekStr: ["周&q ...

  3. [OpenCV入门教程之十二】OpenCV边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合辑

    http://blog.csdn.net/poem_qianmo/article/details/25560901 本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog ...

  4. UVA10529 Dumb Bones

    UVA10529 Dumb Bones go to solution 设$f[i]$表示叠$i$个的骨牌的期望 $O(n)$做法 #include<iostream> #include&l ...

  5. android驱动学习---led实验

    ======================== 驱动: 内核:android-kernel 2.6.36  (必须对应你的板子上内核,不然会出现insmod错误) 目的:通过android应用层用户 ...

  6. ngular6开发不完全笔记(二)-- 管道

    自定义管道 管道(过滤器)为过滤数据显示下列list数据 pip.ts 文件 import { Pipe, PipeTransform } from '@angular/core'; import { ...

  7. 51Nod 1596 搬货物

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1596 思路: 模拟二进制的进位. 这题很坑啊...用c++会超时,用c就 ...

  8. UVa 11248 网络扩容(最大流(需要优化))

    https://vjudge.net/problem/UVA-11248 题意: 给定一个有向网络,每条边均有一个容量.问是否存在一个从点1到点N,流量为C的流.如果不存在,是否可以恰好修改一条弧的容 ...

  9. ongene database

    http://ongene.bioinfo-minzhao.org/index.html

  10. poj 2828 Buy Tickets 树状数组

    Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so ...