vue 组建实现数据的双向绑定
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Helvetica Neue, Arial, sans-serif;
font-size: 14px;
color: #444;
}
table {
border: 2px solid #42b983;
border-radius: 3px;
background-color: #fff;
}
th {
background-color: #42b983;
color: rgba(255,255,255,0.66);
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-user-select: none;
}
td {
background-color: #f9f9f9;
}
th, td {
min-width: 120px;
padding: 10px 20px;
}
th.active {
color: #fff;
}
th.active .arrow {
opacity: 1;
}
.arrow {
display: inline-block;
vertical-align: middle;
width: 0;
height: 0;
margin-left: 5px;
opacity: 0.66;
}
.arrow.asc {
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid #fff;
}
.arrow.dsc {
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 4px solid #fff;
}
#search {
margin-bottom: 10px;
}
</style>
<script src="http://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
<!-- component template -->
<script type="text/x-template" id="grid-template">
<tr>
<td >
{{temp}}
</td>
<td >
{{name}}
</td>
<td >
{{power}}
</td>
<td >
{{product.price}}
</td>
<td >
{{product.stock}}
</td>
<td >
{{product.limitmount}}
</td>
<td >
<demo-select :data="select1" :list="list" :data2="select2" :data3="select3" :product.sync="product"></demo-select>
</td>
</tr>
</script>
<script type="text/x-template" id="select-template">
<select v-model="selected" value="{{product.price}}">
<option v-for="standar in data " v-on:click="notify(product,list)">{{standar}}</option>
</select>
<select v-model="selected2" >
<option v-for="standar in data2 " v-on:click="notify(product,list)">{{standar}}</option>
</select>
<select v-model="selected3" >
<option v-for="standar in data3 " v-on:click="notify(product,list)">{{standar}}</option>
</select>
</script>
<!-- 子组件模板 -->
<template id="child-template">
<input v-model="msg">
<button v-on:click="notify">Dispatch Event</button>
</template>
<!-- 父组件模板 -->
<div id="events-example">
<p>Messages: {{ messages | json }}</p>
<child></child>
</div>
<!-- demo root element -->
<div id="demo">
<table>
<thead>
<tr>
<th >
temp
</th>
<th >
name
</th>
<th>
power
</th>
<th>
price
</th>
<th>
stock
</th>
<th>
limitmount
</th>
<th >
list
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<demo-grid v-for="data in gridData" :temp="data.temp" :name="data.name" :power="data.power" :list="data.datalist"
:select1="data.list" :select2="data.list2" :select3="data.list3" :product="data.datalist[0]" ></demo-grid>
</div>
<div id="dr01"></div>
</body>
</html>
<script>
// register the grid component
Vue.component('demo-grid', {
template: '#grid-template',
props: {
temp :Number,
name :String,
power :String,
list :Array,
product:Object,
select1: Array,
select2: Array,
select3: Array
},
methods: {
childmsg: function (value) {
alter(value);
}
}
})
Vue.component('demo-select', {
template: '#select-template',
props: {
data: Array,
data2: Array,
data3: Array,
list: Array,
type:String,
product:Object
},
data: function () {
return { selected: '',selected2: '',selected3:''
}
},
methods: {
notify: function (val,list) {
var ishas=false;
for(var i=0;i<list.length;i++)
{
var item=list[i];
if(this.selected==item.price&&this.selected2==item.stock&&this.selected3==item.limitmount)
{
this.product=item;
ishas=true;
}
if(!ishas)this.product='';
}
}
}
})
// bootstrap the demo
var demo = new Vue({
el: '#demo',
data: {
gridData:
[{ name: 'Chuck Norris',temp:1, power: Infinity,list:[11,12,13] ,list2:[121,122,123] ,list3:[131,132,133],datalist:[{price:11,stock:121,limitmount:131},{price:131,stock:132,limitmount:133}]},
{ name: 'Bruce Lee',temp:2, power: 9000 ,list:[21,22,23] ,list2:[221,222,223] ,list3:[231,232,233] ,datalist:[{price:121,stock:122,limitmount:123},{price:131,stock:132,limitmount:133}]},
{ name: 'Jackie Chan', temp:3,power: 7000,list:[31,32,33] ,list2:[321,322,323] ,list3:[331,332,333] ,datalist:[{price:121,stock:122,limitmount:123},{price:131,stock:132,limitmount:133}] },
{ name: 'Jet Li',temp:4,power: 8000,list:[41,42,43] ,list2:[421,422,423] ,list3:[431,432,433] ,datalist:[{price:421,stock:422,limitmount:423},{price:131,stock:132,limitmount:133}] }
]
}
})
</script>
vue 组建实现数据的双向绑定的更多相关文章
- vue.js--基础 数据的双向绑定
所谓双向绑定:就是改变modle,就会改变view,改变view,也会改变modle 下面案例,点击getMthod(),获取msg的内容,在点击setMthod()改变msg的内容,你会发现H1的值 ...
- vue 父子组件数据的双向绑定大法
官方文档说明 所有的 prop 都使得其父子 prop 之间形成了一个 单向下行绑定 父级 prop 的更新会向下流动到子组件中,但是反过来则不行 2.3.0+ 新增 .sync 修饰符 以 upda ...
- Vue源码解析---数据的双向绑定
本文主要抽离Vue源码中数据双向绑定的核心代码,解析Vue是如何实现数据的双向绑定 核心思想是ES5的Object.defineProperty()和发布-订阅模式 整体结构 改造Vue实例中的dat ...
- vue中如何实现数据的双向绑定
vue中如何实现数据的双向绑定 实现视图变化数据跟着变:分两步,上面get中的为第二步(即再次读取的时候会调用get方法得到之前设置的值,以此来实现动态改变) 由于直接写obj.name = this ...
- VUE JS 使用组件实现双向绑定
1.VUE 前端简单介绍 VUE JS是一个简洁的双向数据绑定框架,他的性能超过ANGULARJS,原因是实现的机制和ANGULARJS 不同,他在初始化时对数据增加了get和set方法,在数据se ...
- vue2.X props 数据传递 实现组件内数据与组件外的数据的双向绑定
vue2.0 禁止 子组件修改父组件数据 在Vue2中组件的props的数据流动改为了只能单向流动,即只能由组件外(调用组件方)通过组件的DOM属性attribute传递props给组件内,组件内只能 ...
- JavaScript实现数据的双向绑定
接触到Angulr.js和Vue.js后,提到最多的就是双向绑定 下面将用JavaScript实现数据的双向绑定 <!DOCTYPE html> <html> <head ...
- 通过原生js实现数据的双向绑定
通过js实现数据的双向绑定 : Object.defineProperty了解 语法: Object.defineProperty(obj, prop, descriptor) obj 要定义属性的对 ...
- 数据的双向绑定 Angular JS
接触AngularJS许了,时常问自己一些问题,如果是我实现它,会在哪些方面选择跟它相同的道路,哪些方面不同.为此,记录了一些思考,给自己回顾,也供他人参考. 初步大致有以下几个方面: 数据双向绑定 ...
随机推荐
- 用block做事件回调来简化代码,提高开发效率
我们在自定义view的时候,通常要考虑view的封装复用,所以如何把view的事件回调给Controller就是个需要好好考虑的问题, 一般来说,可选的方式主要有target-action和de ...
- 了解JavaScript 数组对象及其方法
数组在我目前学习过的编程语言中都可以见到, 形形色色的方法也数不胜数, 不过功能都一样, 最多也就是方法名稍稍有所不同, 老外也没个准啊, 如果英语比较好的同学对于学习方法(method)来说是很快的 ...
- 3、项目资源的提供 - PMO项目管理办公室
PMO项目管理办公室也需要对项目相关的资源进行提供,从而针对项目的资源也进行标准化和规范化的管理.也就是说,PMO项目管理办公室就是提供项目相关的规范化资源内容,从而统一管理项目相关的内容,达到规范的 ...
- 你该知道的-SQL里的这些新语法-函数
前言 最近帮客户做数据库优化的时候发现客户系统使用了很多函数,自己竟然不知道是干啥的,好歹做过好几年开发的我必然不能忍!于是翻了翻资料自己学习了一下随便也分享给群友. 巧用函数的霸气作用———我做开发 ...
- 错误: “WebForm_DoPostBackWithOptions”未定义
无论是ASP.NET WebForm 还是 ASP.NET MVC项目,在本地程序测试没问题,但是部署在IIS上访问就会出现 错误: “WebForm_DoPostBackWithOptions”未 ...
- 30天的php学习之路——第一天开端
因项目紧急只留给了我4周时间学习php.谨以此文记录我的php学习历程,仅供参考,若有错误请指正. 之前对php有过一些了解,一些语法和习惯和C#差距有些大,所以第一天准备对php中的符号有个全面的了 ...
- HDU 1564 Play a game(巴什博弈)
New Year is Coming! ailyanlu is very happy today! and he is playing a chessboard game with 8600. The ...
- 对比Haproxy和Nginx负载均衡效果
为了对比Hproxy和Nginx负载均衡的效果,分别在测试机上(以下实验都是在单机上测试的,即负载机器和后端机器都在一台机器上)做了这两个负载均衡环境,并各自抓包分析.下面说下这两种负载均衡环境下抓包 ...
- 索引超出了数组界限(Microsoft.SqlServer.Smo)
SSMS连接远程SQL Server服务器是很方便的. 昨天我用SQL Server 2008 SSMS连接SQL Server 2012竟然报错,如下图: 在网上搜了,参考这个参考那个,太啰嗦了,确 ...
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...