Slider.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <!-- 滑块 -->
  3. <div class="slider">
  4. <!-- 标题部分 -->
  5. <div class="scienceTitle">
  6. <h5>{{ navigation1[16]?.alias }}</h5>
  7. <!-- <p class="title">
  8. <span v-for="(item, index) in scienceTitleList" :key="index" @mousemove="changeUl(index)">
  9. <a href="#">{{ item.title }}</a>
  10. </span>
  11. </p> -->
  12. </div>
  13. <!-- 标题下内容列表 -->
  14. <div class="box">
  15. <transition name="fade">
  16. <div class="scienceListBox">
  17. <ul class="scienceList">
  18. <li v-for="item in boxData1">
  19. <img :src="item.imgurl">
  20. <p>{{ item.title }}</p>
  21. </li>
  22. </ul>
  23. <!-- <ul class="scienceList">
  24. <li v-for="item in 6">
  25. <img src="../../static/images/sgbhsihfgisdfaasda45632113_A_Chinese_farmer_carrying_a_hoe_is_h_1ba32eee-c498-4dd7-9cd9-013568c09db7.png"
  26. alt="">
  27. <p>市农业农村局关于印发连云港市市级…</p>
  28. </li>
  29. </ul>
  30. <ul class="scienceList">
  31. <li v-for="item in 6">
  32. <img src="../../static/images/rgmezdvz_19982_On_a_vast_and_boundless_wheat_field_many_harvest_5b5cfeda-ef17-4551-a935-5f8e3f799b69.png"
  33. alt="">
  34. <p>市农业农村局关于印发连云港市市级…</p>
  35. </li>
  36. </ul>
  37. <ul class="scienceList">
  38. <li v-for="item in 6">
  39. <img src="../../static/images/rgmezdvz_19982_A_Chinese_farmer_carrying_a_hoe_is_hoeing_the_fi_a036c7b3-b05e-4d3d-a371-0bed91ec1ff8(1).png"
  40. alt="">
  41. <p>市农业农村局关于印发连云港市市级…</p>
  42. </li>
  43. </ul> -->
  44. </div>
  45. </transition>
  46. </div>
  47. </div>
  48. </template>
  49. <script setup>
  50. const nuxtApp = useNuxtApp();
  51. const axios = nuxtApp.$axios;
  52. const radio1 = ref('1')
  53. //获取导航一的栏目
  54. const navigation1 = ref("");
  55. const navigateList = async () => {
  56. try {
  57. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  58. console.log('一级导航', response.data);
  59. navigation1.value = response.data;
  60. } catch (error) {
  61. console.error(error);
  62. }
  63. }
  64. const boxData1 = ref("");
  65. const getWebsiteModelArticles = async () => {
  66. try {
  67. const response = await axios.get(`/web/getWebsiteModelArticles?catid=${16}&level=${1}&pagesize=${6}`);
  68. console.log('一级导航', response.data);
  69. boxData1.value = response.data;
  70. } catch (error) {
  71. console.error(error);
  72. }
  73. }
  74. onMounted(() => {
  75. // 一级导航
  76. navigateList()
  77. getWebsiteModelArticles()
  78. })
  79. let scienceTitleList = [
  80. {
  81. id: 1,
  82. title: "农产畅销"
  83. },
  84. {
  85. id: 2,
  86. title: "农业在线"
  87. },
  88. {
  89. id: 3,
  90. title: "农产行情"
  91. },
  92. {
  93. id: 4,
  94. title: "名优特产"
  95. }
  96. ]
  97. //鼠标移入标题时,下方内容会发生变化
  98. // let changeUl = (index) => {
  99. // // console.log(index);
  100. // if (process.browser) {
  101. // let scienceListBox = document.querySelector('.scienceListBox');
  102. // let titleList = document.querySelectorAll('.title>span>a')
  103. // for (let i = 0; i < titleList.length; i++) {
  104. // titleList[i].className = ''
  105. // }
  106. // titleList[index].setAttribute('class', 'current')
  107. // if (index == 0) {
  108. // scienceListBox.style.left = 0
  109. // } else if (index == 1) {
  110. // scienceListBox.style.left = "-790px"
  111. // } else if (index == 2) {
  112. // scienceListBox.style.left = "-1580px"
  113. // } else if (index == 3) {
  114. // scienceListBox.style.left = "-2370px"
  115. // }
  116. // }
  117. // }
  118. </script>
  119. <style lang="less" scoped>
  120. // 标题
  121. .scienceTitle {
  122. height: 37px;
  123. h5 {
  124. float: left;
  125. width: 96px;
  126. height: 34px;
  127. font-family: PingFang SC, PingFang SC;
  128. font-weight: 600;
  129. font-size: 24px;
  130. color: #000000;
  131. line-height: 28px;
  132. text-align: left;
  133. font-style: normal;
  134. text-transform: none;
  135. margin-right: 20px;
  136. }
  137. >p {
  138. float: left;
  139. height: 37px;
  140. line-height: 30px;
  141. >span {
  142. display: inline-block;
  143. height: 20px;
  144. line-height: 20px;
  145. text-align: center;
  146. margin: 4px 0px 3px;
  147. padding: 0 20px;
  148. border-right: 1px solid #ccc;
  149. >a {
  150. display: inline-block;
  151. padding-bottom: 11px;
  152. font-family: PingFang SC, PingFang SC;
  153. font-weight: 500;
  154. font-size: 20px;
  155. color: #666666;
  156. line-height: 20px;
  157. font-style: normal;
  158. text-transform: none;
  159. box-sizing: border-box;
  160. }
  161. .current {
  162. color: #139602;
  163. border-bottom: 1px solid #139602;
  164. }
  165. }
  166. >span:nth-child(4) {
  167. border-right: none;
  168. }
  169. >span:hover>a {
  170. color: #139602;
  171. border-bottom: 1px solid #139602;
  172. }
  173. }
  174. }
  175. .box {
  176. width: 790px;
  177. height: 570px;
  178. position: relative;
  179. overflow: hidden;
  180. }
  181. .fade-in {
  182. animation: fadeIn 1s ease-in-out;
  183. }
  184. .fade-enter-from,
  185. .fade-leave-to {
  186. opacity: 0;
  187. }
  188. .fade-enter-to,
  189. .fade-leave-from {
  190. opacity: 1;
  191. }
  192. .fade-enter-active,
  193. .fade-leave-active {
  194. transition: opacity 1s ease;
  195. }
  196. .scienceListBox {
  197. width: 3160px;
  198. height: 570px;
  199. position: absolute;
  200. top: 0;
  201. left: 0;
  202. transition: all 3s linear 0;
  203. }
  204. // 标题下列表
  205. .scienceList {
  206. width: 790px;
  207. height: 570px;
  208. float: left;
  209. margin-top: 17px;
  210. >li {
  211. width: 250px;
  212. height: 276px;
  213. float: left;
  214. margin-right: 20px;
  215. position: relative;
  216. >img {
  217. width: 250px;
  218. height: 220px;
  219. }
  220. >p {
  221. width: 254px;
  222. display: -webkit-box;
  223. -webkit-box-orient: vertical;
  224. -webkit-line-clamp: 2;
  225. overflow: hidden;
  226. text-overflow: ellipsis;
  227. word-break: break-all;
  228. height: 48px;
  229. overflow: hidden;
  230. font-family: PingFang SC, PingFang SC;
  231. font-weight: 600;
  232. font-size: 18px;
  233. color: #333333;
  234. line-height: 24px;
  235. text-align: left;
  236. font-style: normal;
  237. text-transform: none;
  238. }
  239. >p:hover {
  240. color: #139602;
  241. }
  242. }
  243. >li:nth-child(3),
  244. >li:nth-child(6) {
  245. margin-right: 0;
  246. }
  247. >li::before {
  248. content: "";
  249. display: inline-block;
  250. width: 40px;
  251. height: 20px;
  252. position: absolute;
  253. top: 0;
  254. right: 0;
  255. background-image: url("../../static/images/Component 209.png");
  256. }
  257. }
  258. </style>