1. <template>
    2. <view id="container">
    3. <view v-for="item of movie" :key="item.id" class="list">
    4. <image :src="item.pic" class="i"></image>
    5. <view class="title">{{ item.title }}</view>
    6. <view class="span">
    7. <block v-for="item of item.star" :key="item.id">
    8. <image
    9. class="star"
    10. v-if="item >= 1.5"
    11. src="../../../image/star.png"
    12. />
    13. <image
    14. class="star"
    15. v-else-if="item >= 1"
    16. src="../../../image/ban-star.png"
    17. />
    18. <image class="star" v-else src="../../../image/no-star.png" />
    19. </block>
    20. <view class="raiting">{{ item.raiting }}</view>
    21. </view>
    22. </view>
    23. </view>
    24. </template>
    25. <script>
    26. import "./index.scss";
    27. import Taro from "@tarojs/taro";
    28. export default {
    29. data() {
    30. return {
    31. movie: [],
    32. };
    33. },
    34. mounted() {
    35. Taro.request({
    36. url: "http://47.113.106.101:6505/api/movie/top250",
    37. data: {},
    38. header: {
    39. "content-type": "application/json",
    40. },
    41. success: (res) => {
    42. var movie = res.data.result;
    43. movie.forEach((item) => {
    44. item.star = handleStart(item.raiting);
    45. });
    46. this.movie = movie;
    47. },
    48. });
    49. },
    50. };
    51. function handleStart(value) {
    52. var arr = [];
    53. for (let i = 0; i < 5; i++) {
    54. if (value > 2) {
    55. arr.push(2);
    56. } else if (value > 0) {
    57. arr.push(value);
    58. } else {
    59. arr.push(0);
    60. }
    61. value -= 2;
    62. }
    63. return arr;
    64. }
    65. </script>
    66. <style>
    67. #container {
    68. margin-left: auto;
    69. margin-right: auto;
    70. display: grid;
    71. grid-template-columns: repeat(3,33vw);
    72. justify-items: center;
    73. align-items: center;
    74. }
    75. .list {
    76. padding: 20px;
    77. }
    78. .title {
    79. font-size: 25px;
    80. text-align: center;
    81. }
    82. .star {
    83. width: 20px;
    84. height: 20px;
    85. }
    86. .i {
    87. width: 150rpx;
    88. height: 170rpx;
    89. }
    90. .list .span {
    91. width: 120px;
    92. margin-left: auto;
    93. margin-right: auto;
    94. }
    95. .raiting{
    96. text-align: center;
    97. }
    98. </style>