使用vue2实现购物车和地址选配功能

网友投稿 270 2023-02-10


使用vue2实现购物车和地址选配功能

首先,vue基础js写法

new Vue({

el:"#app",

//模型

data:{

},

filters:{

},

mounted:function(){

this.$nextTick(function(){

//初始化调用

});

},

computed:{

//实时计算

},

methods:{

}

});

v-for

v-model

(实时更新)

v-bind

filters过滤器的使用

1.html引用方式

2.过滤器

filters:{

formatMoney:function(value,type){

return "¥"+value.toFixed(2)+ type;

}

},

3.全局过滤器(写在new Vue的外面)

Vue.filter("money",function(value,type){

return "¥"+value.toFixed(2) + type; //保留两位小数 结果eg:¥19.00元

});

调用methods中的方法:

@click="method(param)"

//或者

@click="delFlag=false"

@click="limitNum=addressList.length"

computed 实时计算

如下:默认显示三条数据,点击more 显示所有

more

data:{

limitNum:3

},

computed:{

filterAddress:function(){

return this.addressList.slice(0,this.limitNum);

}

},

先提出一两个经典的实例

1.以下实现了对循环卡片的点击 选中

@click="currentIndex=index">

2.以下实现了对固定卡片的点击 选中

<li v-bind:class="{'check':shippingMethod==1}" @click="shippingMethod=1">

题外话:由于本人小白,学一点是一点,额外记录一下辅助弹出框 遮罩层的写法

vue2的js语法 贴几个 方便查用

1.调用后端方法

var _this = this;

this.$http.get("data/address.json").then(function(response){

_this.addressList = response; //这里不能直接用this 此this非彼this 所以只能声明_this

});

//以下为ES6写法,就可以直接用this了

let _this = this; //没用,就放这看看~

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

this.productList = res.data.result.list;

});

2.forEach循环

this.productList.forEach(function(item,index){

if(typeof item.checked == 'undefined'){

//如果item中没有checked属性 在item对象中添加checked属性,值为true

_this.$set(item,"checked",true);//局部注册

Vue.set(item,"checked",true);//全局注册

}

});

附上链接:码云地址vue2_study

总结

以上所述是给大家介绍的使用vue2实现购物车和地址选配功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springmvc 传递和接收数组参数的实例
下一篇:国外API接口管理(对外api)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~