练习题3_商品卡.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./js/vue.js"></script>
  8. <script src="./js/ajax.js"></script>
  9. <style>
  10. .product-card {
  11. width: 234px;
  12. /* 如果数值为0 那么单位可以省略 如果值是0.X 0也可以省略 0.5=.5 */
  13. box-shadow: 0 0 10px rgba(0, 0, 0, .5);
  14. padding: 10px;
  15. text-align: center;
  16. float: left;
  17. margin-right: 20px;
  18. }
  19. .product-img img {
  20. width: 100%;
  21. }
  22. .product-title {
  23. /* 文字大小尽量不要小于12px */
  24. font-size: 14px;
  25. font-weight: 400;
  26. color: #333;
  27. }
  28. .product-info {
  29. font-size: 12px;
  30. color: #b0b0b0;
  31. text-wrap: nowrap;
  32. overflow: hidden;
  33. text-overflow: ellipsis;
  34. margin-top: 10px;
  35. margin-bottom: 20px;
  36. }
  37. .product-price span {
  38. color: #ff6700;
  39. }
  40. .product-price del {
  41. color: #b0b0b0;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div id="app">
  47. <div class="btn">
  48. <button v-on:click="getProduct">获取商品</button>
  49. </div>
  50. <div class="product-list">
  51. <div class="product-card" v-for="item in productList">
  52. <div class="product-img">
  53. <img :src="item.pic" alt="img">
  54. </div>
  55. <div class="product-title">{{item.prodName}}</div>
  56. <div class="product-info">{{item.brief}}</div>
  57. <div class="product-price">
  58. <span>{{item.price}}</span>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <script>
  64. new Vue({
  65. el: "#app",
  66. data: {
  67. productList: []
  68. },
  69. methods: {
  70. getProduct() {
  71. let _this = this;
  72. ajax("GET","http://shop-api.edu.koobietech.com/prod/tagProdList",function(res){
  73. console.log(res.data[0].productDtoList);
  74. _this.productList = res.data[0].productDtoList;
  75. })
  76. }
  77. }
  78. })
  79. </script>
  80. </body>
  81. </html>