第四节 v-on实现金额动态计算

用¥金额 进行格式处理,可以使用原生js进行转换,但是在vuei,使用filter过滤器更加方便

注:

1.es6语法=>和import等

好处在于res参数后的function函数内的this作用域,不弄在外部声明变量了。

methods:{

cartView:function(){

let _this=this;

this.$http.get("data/cartData.json",{"id":123}).then( res=>{

this.productList =res.body.result.productList;
this.totalMoney=res.body.result.totalMoney;

}); }}

2.全局过滤器:可以在任何页面使用

html:{{item.productPrice*item.productQuentity | money('元')}}
js:
       Vue.filter("money",function (value,type) {
return"¥"+value.toFixed(2)+type;
})

代码:

<ul class="cart-item-list">
<li v-for="(item,index) in productList">
<!--v-for="item in productList"这是vue1.0的用法-->
<div class="cart-tab-1">
<!-- 单选 -->
<div class="cart-item-check">
<a href="javascipt:;" class="item-check-btn">
<svg class="icon icon-ok"><use xlink:href="#icon-ok"></use></svg>
</a>
</div>
<!-- 商品图片 -->
<div class="cart-item-pic">
<img v-bind:src="item.productImage" alt="烟">
<!--src="{{item.productImage}}"貌似不能使用-->
<!--v-bind是比较好的办法,浏览器解析字符串直接写src会报错什么的-->
</div>
<!-- 商品名称 -->
<div class="cart-item-title">
<div class="item-name">{{item.productName+":"+index}}</div>
<!--{{item.productName+":"+index}}-->
</div>
<!-- 赠品 -->
<div class="item-include">
<dl>
<dt>赠送:</dt>
<dd v-for="part in item.parts" v-text="part.partsName"></dd>
</dl>
</div>
</div>
<!-- 单价 -->
<div class="cart-tab-2">
<div class="item-price">{{item.productPrice | formatMoney}}</div>
</div>
<div class="cart-tab-3">
<div class="item-quantity">
<div class="select-self select-self-open">
<div class="quentity">
<a href="javascript:;">-</a>
<input type="text" v-model="item.productQuentity">
<!--双向数据绑定功能,实现总金额实时变化功能-->
<a href="javascript:;">+</a>
</div>
</div>
<div class="item-stock">有货</div>
</div>
</div>
<div class="cart-tab-4">
<!-- 总金额 -->
<div class="item-price-total">{{item.productPrice*item.productQuentity | formatMoney}}</div>
</div>
<!-- 删除功能 --> <div class="cart-tab-5">
<div class="cart-item-opration">
<a href="javascript:;" class="item-edit-btn">
<svg class="icon icon-del"><use xlink:href="#icon-del"></use></svg>
</a>
</div>
</div> </li>
</ul>js:
/**
* Created by zs1414030853 on 2017/2/24.
*/
/*完整vue实例*/
var vm=new Vue({
el:"#app",
data:{
totalMoney:0,
productList:[]
/*初始值*/
}, filters:{
formatMoney:function (value) {
return"¥"+value.toFixed(2);
}
/*局部过滤器只能在实例的范围内使用*/
}, mounted:function () {
this.$nextTick(function () { });/*此时this和vm是等同的,这是mounted和ready的vue1和2的区别*/
this.cartView(); }, methods:{
cartView: function () {
var _this =this;
/* this.$http.jsonp*/
this.$http.get("data/cart.json",{"id":123}).then(function (res) {
_this.productList =res.body.result.productList;
_this.totalMoney=res.body.result.totalMoney;
/*在运行的时候打断点可以查看res等属性和包含的方法值等*/
});
}
} });
												

VUE2.0实现购物车和地址选配功能学习第四节的更多相关文章

  1. VUE2.0实现购物车和地址选配功能学习第七节

    第七节 卡片选中,设置默认 1.卡片选中html:<li v-for="(item,index) in filterAddress" v-bind:class="{ ...

  2. VUE2.0实现购物车和地址选配功能学习第六节

    第六节 地址列表过滤和展开所有的地址 html:<li v-for="(item,index) in filterAddress">js: new Vue({ el:' ...

  3. VUE2.0实现购物车和地址选配功能学习第五节

    第五节 单件商品金额计算和单选全选功能 1.vue精髓在于操作data模型来改变dom,渲染页面,而不是直接去改变dom 2.加减改变总金额功能: html:<div class="c ...

  4. VUE2.0实现购物车和地址选配功能学习第三节

    第三节 使用v-for渲染商品列表 1.使用vue-resource插件引入json数据 (注:在谷歌中调试打断点-- ,console还可以输出vm,res等属性列表,或者productList等一 ...

  5. VUE2.0实现购物车和地址选配功能学习第二节

    第二节 创建VUE实例 购物车项目计划: 1.创建一个vue实例 2.通过v-for指令渲染产品数据 3.使用filter对金额和图片进行格式化 4.使用v-on实现产品金额动态计算 5.综合演示 ① ...

  6. VUE2.0实现购物车和地址选配功能学习第一节(来源--慕课网河畔一角)

    第一节  vue知识 vue-resource:和后台交互的一个插件,实现get.post和jsonp等功能.(替代jQuery) vue特点: 1.易用:通过创建vue实例,{{}}绑定数据十分方便 ...

  7. 关于慕课网《使用vue2.0实现购物车和地址选配功能》的总结

    视频学习网址:http://www.imooc.com/learn/796 源码打包:https://codeload.github.com/fachaoshao/Vue-ShoppingCart/z ...

  8. vue2.0实现购物车功能

    购物车功能是一件比较繁琐的事情,逻辑功能太多,今天就用vue2.0实现一个简单的购物车功能,数据都本地自己写的假数据 功能列表: 1.全选和单选结算 2.减少和增加数量 3.商品的删除 界面搭建以及布 ...

  9. vue购物车和地址选配(三)

    参考资料:vue.js官网 项目演示: 项目源代码: 核心代码及踩坑 删除: new Vue({ el:'#app', data:{ productlist:[], totalMoney:0, che ...

随机推荐

  1. SQL四种语言

    1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema ...

  2. 黄聪:VPS用轻松备份工具备份Wordpress,文件夹通配符

    db;log;wp-admin;wp-includes;temp;upgrade;twentyfourteen;twentyfifteen;twentysixteen;twentythirteen;t ...

  3. win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程——转载

    操作系统:Microsoft Windows 7 旗舰版(32位) 数据库版本:SQL Server 2005 简体中文开发板 数据库下载链接:http://pan.baidu.com/share/l ...

  4. iOS 之 内存管理

    凡是alloc copy mutablecopy init 声明的变量,都需要通过手动的方式进行释放,realse. 如果 copy一个对象,则拥有了拷贝的对象,要负责释放. 如果 保持(retain ...

  5. 模块划分--MVVM指南(课程学习)

    实现流水化开发,需要使用“模块划分”的程序开发方式.如此,团队里的每个人负责某项\某几项特定的技术领域,在特定的技术领域更加专业.这样,每个人的效率更高.在专业的技能更熟练,更深入,也会提高队员的成就 ...

  6. Linux目录结构示意详解图

  7. QT第六天学习

    基本事件: 鼠标事件 键盘事件 绘制事件 1.QT中的事件: 事件是对各应用程序需要知道的由应用程序内部或外部产生的事情或动作的通称. QT中事件的处理: 在QT中使用一个对象来表示一个事件,继承自Q ...

  8. Struts2拦截器介绍

    一.拦截器简介 Struts拦截器和Action的关系如图: 为了在使用拦截器时制定参数值,应通过<interceptor-ref -/>元素添加<param -/>子元素来为 ...

  9. ORA-01555经典错误

    --创建undo表空间时固定表空间的大小 sys@TDB112>create undo tablespace undo_small 2  datafile'/u01/app/oracle/ora ...

  10. 在ASP.NET MVC3项目中,自定义404错误页面

    在Web开发中,用户体验是至关重要的,一个友好的网站自然少不了自定义404错误页面. 让笔者为大家介绍404错误页面在ASP.NET MVC3项目中的配置: 第一步,在项目的Web.config文件中 ...