网易云

App.vue

  1. <template>
  2. <div id="app">
  3. <Music :item="item" v-for="item of music" :key="item.id"></Music>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { Component, Vue, Provide } from "vue-property-decorator";
  8. import Music from "./components/Music.vue";
  9. import axios from 'axios';
  10. @Component({
  11. components: {
  12. Music,
  13. },
  14. })
  15. export default class App extends Vue {
  16. @Provide() music: Array<Object> = [];
  17. mounted():void{
  18. axios.get("http://localhost:3000/top/playlist?cat=华语").then(res =>{
  19. console.log(res.data.playlists);
  20. this.music= res.data.playlists;
  21. })
  22. }
  23. }
  24. </script>
  25. <style>
  26. #app{
  27. width: 800px;
  28. margin: auto;
  29. display: grid;
  30. grid-template-columns: repeat(3,1fr);
  31. grid-gap: 5px;
  32. justify-items: center;
  33. }
  34. </style>

Music.vue

  1. <template>
  2. <div class="item">
  3. <!-- 快捷键:vbase -->
  4. <img :src="item.coverImgUrl" alt="" />
  5. <p class="title">{{ item.name | handleFilter}}</p>
  6. <span class="count">{{ item.playCount | handleSum}}</span>
  7. </div>
  8. </template>
  9. <script lang="ts">
  10. import {Component, Vue,Prop} from "vue-property-decorator";
  11. @Component({
  12. filters: {
  13. handleSum(value:any) {
  14. if (value > 100000000) {
  15. return Math.floor(value / 100000000) + "亿";
  16. } else if (value > 10000) {
  17. return Math.floor(value / 10000) + "万";
  18. } else {
  19. return value;
  20. }
  21. },
  22. handleFilter(val:any) {
  23. if (val.length > 14) {
  24. return val.slice(0, 14) + "...";
  25. }
  26. return val;
  27. },
  28. },
  29. })
  30. export default class Hello extends Vue {
  31. @Prop() item !:object;
  32. }
  33. </script>
  34. <style scoped>
  35. .item {
  36. width: 200px;
  37. position: relative;
  38. }
  39. img {
  40. width: 200px;
  41. height: 200px;
  42. }
  43. .title {
  44. font-size: 14px;
  45. }
  46. .count {
  47. position: absolute;
  48. top: 10px;
  49. right: 10px;
  50. color: rgb(120, 228, 228);
  51. }
  52. </style>