index.js

实战篇:利用计算属性、指令等知识开发购物车源代码

var app = new Vue({

    el:'#app',

    data:{

      list:[

          {id:1,name:'iPhone7',price:6188,count:1},

          {id:2,name:'iPad Pro',price:58888,count:1},

          {id:2,name:'MacBook Pro',price:2148,count:1},

    ]

  },

computed:{

    totalPrice:function(){

       var total = 0;

       for(var i=0;i<list.length;i++){

       total+=list[i].price * list[i]*count;

   }

        return total.toString.replace(\/B(?=(\d{3})+$)/g,',');

 }

},

    methods:{

       hanldReduce:function(index){

         if(this.list[index].count===1){

          return;

        }else{

          return  this.list[index].count--;

}

},

  handleAdd:function(index){

       return this.list[index].count++;

 },

 handelRemove:function(index){

        this.list[index].splice(index,1);

   }

  }

});

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 6,174评论 0 2
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,190评论 0 13
  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 14,750评论 0 38
  • 前几天,领导喝多了,讲起了他不幸的的婚姻生活,在想想自己看到的他俩的相处模式,我觉得造成两人现在状态的最主要原因就...
    伊予yisheng阅读 2,394评论 0 0
  • 无仙 第一章:雷霆血海 一如既往的入夜,那不断划破天际的血色闪电却让无数人无眠,无尽的血色雷霆在那无尽的黑色夜空中...
    Zy温度阅读 1,859评论 1 1

友情链接更多精彩内容