练习3_商品列表.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. <style>
  8. /* css reset */
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. li{
  14. list-style: none;
  15. width: 200px;
  16. padding: 30px;
  17. }
  18. ul{
  19. display: flex;
  20. flex-wrap: wrap;
  21. }
  22. li{
  23. box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  24. margin: 30px;
  25. }
  26. .goods-img img{
  27. width: 200px;
  28. }
  29. .goods-title{
  30. font-size: 20px;
  31. margin-top: 10px;
  32. width: 100%;
  33. overflow: hidden;
  34. white-space: nowrap;
  35. text-overflow: ellipsis;
  36. }
  37. .goods-desc,.goods-price{
  38. margin-top: 10px;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div id="app">
  44. <ul>
  45. <li v-for="item in goodsList">
  46. <div class="goods-img">
  47. <img v-bind:src="item.pic" alt="商品图片">
  48. </div>
  49. <h2 class="goods-title">{{item.prodName}}</h2>
  50. <p class="goods-desc">{{item.brief}}</p>
  51. <p class="goods-price">¥{{item.price}}</p>
  52. </li>
  53. </ul>
  54. </div>
  55. <script src="./js/vue.js"></script>
  56. <script src="./js/ajax.js"></script>
  57. <script>
  58. new Vue({
  59. el: '#app',
  60. data:{
  61. goodsList:[]
  62. },
  63. created(){
  64. // 调用获取商品列表方法
  65. this.getGoodsList();
  66. },
  67. methods:{
  68. // 获取商品列表
  69. getGoodsList(){
  70. // let _this = this;
  71. // 发送ajax请求
  72. ajax("GET","http://shop-api.edu.koobietech.com/prod/tagProdList",(res)=>{
  73. // 处理响应数据
  74. let _goodsList = res.data[0].productDtoList;
  75. // console.log(_goodsList);
  76. // console.log(_this)
  77. // console.log(this);
  78. this.goodsList = _goodsList;
  79. })
  80. }
  81. }
  82. })
  83. </script>
  84. </body>
  85. </html>