waterflow-fit-height.uvue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view style="flex: 1;">
  3. <waterflow style="flex: 1;" cross-axis-gap="5" main-axis-gap="5">
  4. <flow-item v-for="(item, index) in list" :key="index" @click="itemClick(item['author_name'] as string | null)">
  5. <view class="item">
  6. <image class="img" :fade-show="true" :src="item['cover']" mode="widthFix"></image>
  7. <text class="name">{{ item['author_name'] }}</text>
  8. <text class="title">{{ item['title'] }}</text>
  9. <text class="time">{{ item['published_at'] }}</text>
  10. </view>
  11. </flow-item>
  12. </waterflow>
  13. </view>
  14. </template>
  15. <script setup>
  16. const list = ref<UTSJSONObject[]>([] as UTSJSONObject[])
  17. const itemClick = (title : string | null) => {
  18. if (title != null) {
  19. uni.showToast({
  20. title: title,
  21. icon: 'none'
  22. })
  23. }
  24. }
  25. function getList() {
  26. uni.showLoading({
  27. title: 'loading...'
  28. })
  29. uni.request<UTSJSONObject[]>({
  30. url: 'https://unidemo.dcloud.net.cn/api/news?column=title,author_name,cover,published_at',
  31. method: "GET",
  32. success: (res : RequestSuccess<UTSJSONObject[]>) => {
  33. if (res.statusCode == 200) {
  34. const result = res.data
  35. if (result != null) {
  36. list.value = result
  37. }
  38. }
  39. },
  40. complete: () => {
  41. uni.hideLoading()
  42. }
  43. });
  44. }
  45. onLoad((_: OnLoadOptions) => {
  46. getList()
  47. })
  48. </script>
  49. <style lang="scss">
  50. .item {
  51. width: 100%;
  52. border-radius: 8px;
  53. background-color: white;
  54. .img {
  55. width: 100%;
  56. border-radius: 5px;
  57. }
  58. .name {
  59. font-size: 18px;
  60. font-weight: bold;
  61. margin: 10px;
  62. }
  63. .title {
  64. font-size: 14px;
  65. margin: 0 10px;
  66. color: gray;
  67. }
  68. .time {
  69. font-size: 14px;
  70. color: gray;
  71. margin: 10px;
  72. }
  73. }
  74. </style>