Blogger Information
Blog 34
fans 0
comment 0
visits 24464
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS框架 -(三)vue实战,使用Vue重写购物车
CY明月归
Original
593 people have browsed it

1. 将之前的原生购物车案例, 用计算属性或侦听器进行改写

  1. app = {
  2. data() {
  3. return {
  4. price1: 100,
  5. num1: 1,
  6. price2: 500,
  7. num2: 1,
  8. nums:0,
  9. totalamount:0,
  10. disamount: 600,
  11. dis: 0,
  12. };
  13. },
  14. //计算属性: 访问器属性实现的
  15. computed: {
  16. payAmount1() {
  17. return this.price1 * this.num1;
  18. },
  19. payAmount2() {
  20. return this.price2 * this.num2;
  21. },
  22. totalAmount() {
  23. return this.payAmount1 + this.payAmount2;
  24. },
  25. //控制优惠折扣显示
  26. flag() {
  27. return this.dis > 0;
  28. },
  29. },
  30. // 侦听器属性
  31. watch: {
  32. //current,origin
  33. totalAmount(a) {
  34. switch (true) {
  35. case a >= 1000 && a < 2000:
  36. //向上取整,避免出现计算精度问题
  37. this.disamount =Math.ceil( a * 0.9);
  38. break;
  39. case a >= 2000 && a < 3000:
  40. this.disamount =Math.ceil( a * 0.8);
  41. break;
  42. case a >= 3000:
  43. this.disamount =Math.ceil( a * 0.7);
  44. break;
  45. default:
  46. this.disamount = a;
  47. }
  48. this.dis = a - this.disamount;
  49. },
  50. },
  51. methods: {
  52. },
  53. };
  54. Vue.createApp(app).mount(".app");

2. 可选大作业 : 仿 php中文网 app 首页

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post