VUE2.0实现购物车和地址选配功能学习第三节
第三节 使用v-for渲染商品列表
1.使用vue-resource插件引入json数据
(注:在谷歌中调试打断点--
,console还可以输出vm,res等属性列表,或者productList等一些值。如打出vm可以查看vue实例包含的属性和方法等)
html:
<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}}</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}}</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:{ }, mounted:function () {
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等属性和包含的方法值等*/
});
}
} });
数据cart.json:
{
"message":"",
"status":"1",
"result":{
"totalMoney":0,
"productList":[
{
"productId":"10001",
"productName":"黄鹤楼香烟",
"productPrice":19,
"productQuentity":3,
"productImage":"img/goods-1.jpg",
"parts":[
{
"partsId":"a001",
"partsName":"打火机"
},
{
"partsId":"a002",
"partsName":"XXX"
}
]
},
{
"productId":"10002",
"productName":"加多宝",
"productPrice":8,
"productQuentity":2,
"productImage":"img/goods-2.jpg",
"parts":[
{
"partsId":"a001",
"partsName":"吸管"
}
]
},
{
"productId":"10003",
"productName":"耳机",
"productPrice":39,
"productQuentity":1,
"productImage":"img/ear.jpeg",
"parts":[]
}
]
}
}
VUE2.0实现购物车和地址选配功能学习第三节的更多相关文章
- VUE2.0实现购物车和地址选配功能学习第七节
第七节 卡片选中,设置默认 1.卡片选中html:<li v-for="(item,index) in filterAddress" v-bind:class="{ ...
- VUE2.0实现购物车和地址选配功能学习第六节
第六节 地址列表过滤和展开所有的地址 html:<li v-for="(item,index) in filterAddress">js: new Vue({ el:' ...
- VUE2.0实现购物车和地址选配功能学习第五节
第五节 单件商品金额计算和单选全选功能 1.vue精髓在于操作data模型来改变dom,渲染页面,而不是直接去改变dom 2.加减改变总金额功能: html:<div class="c ...
- VUE2.0实现购物车和地址选配功能学习第四节
第四节 v-on实现金额动态计算 用¥金额 进行格式处理,可以使用原生js进行转换,但是在vuei,使用filter过滤器更加方便 注: 1.es6语法=>和import等 好处在于res参数后 ...
- VUE2.0实现购物车和地址选配功能学习第二节
第二节 创建VUE实例 购物车项目计划: 1.创建一个vue实例 2.通过v-for指令渲染产品数据 3.使用filter对金额和图片进行格式化 4.使用v-on实现产品金额动态计算 5.综合演示 ① ...
- VUE2.0实现购物车和地址选配功能学习第一节(来源--慕课网河畔一角)
第一节 vue知识 vue-resource:和后台交互的一个插件,实现get.post和jsonp等功能.(替代jQuery) vue特点: 1.易用:通过创建vue实例,{{}}绑定数据十分方便 ...
- 关于慕课网《使用vue2.0实现购物车和地址选配功能》的总结
视频学习网址:http://www.imooc.com/learn/796 源码打包:https://codeload.github.com/fachaoshao/Vue-ShoppingCart/z ...
- vue2.0实现购物车功能
购物车功能是一件比较繁琐的事情,逻辑功能太多,今天就用vue2.0实现一个简单的购物车功能,数据都本地自己写的假数据 功能列表: 1.全选和单选结算 2.减少和增加数量 3.商品的删除 界面搭建以及布 ...
- vue购物车和地址选配(三)
参考资料:vue.js官网 项目演示: 项目源代码: 核心代码及踩坑 删除: new Vue({ el:'#app', data:{ productlist:[], totalMoney:0, che ...
随机推荐
- 315.Count of Smaller Numbers After Self My Submissions Question
You are given an integer array nums and you have to return a new counts array. Thecounts array has t ...
- PHP mysqli连接MySQL数据库
1. 开启PHP的API支持 (1)首先修改您的php.ini的配置文件.查找下面的语句:;extension=php_mysqli.dll将其修改为:extension=php_mysqli.dll ...
- 二分法查找-java案例详解
/** * 功能:二分查找 * 基本思想: * 假设数据是按升序排序的,对于给定值x,从序列的中间位置开始比较, * 如果当前位置值等于x,则查找成功:若x小于当前位置值,则在数列的 * 前半段中查找 ...
- 聚类系数(clustering coefficient)计算
转自http://blog.csdn.net/pennyliang/article/details/6838956 Clustering coefficient的定义有两种:全局的和局部的. 全局的算 ...
- Chrome中java因过期而遭到阻止
http://www.cnblogs.com/jifeng/p/3453322.html 在Chrome快捷方式图标上右击,选[属性],然后在[目标]一栏的末尾添加这么一段命令(flag): --al ...
- Canvas 阴影效果
shadow <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- HDU1556(树状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- vue.js中ajax请求
<div id="app"> <table style="border-collapse: collapse"> <thead&g ...
- react native ios打包到真机
每当在模拟器上完成了开发,都想到真机上秀秀,正好前段时候买了一个mac,哈哈有机会了.前篇文章以android为例,这里就以ios为例,讲一下打包到iphone真机的流程. 一.前置 1.首先你得有一 ...
- spring-mvc.xml配置
1.自动扫描 <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> <context:component-scan base-pac ...