• 【vue3】实现筛选页组件(深层嵌套循环数据切换)的封装和调用


    一、页面布局截图

    1、首次进入该页面,默认选中初中项,并加载右侧初中相关的课程列表

    2、筛选页(当点击初中项下的科目项,展示右侧筛选弹窗)

    3、切换无内容项展示

    图例1:无科目以及无课程列表的截图

     

    图例2:有科目无右侧筛选弹窗内容截图

     二、筛选展示的数据结构如下(数据内容仅供参考)

    1. let data=[
    2. {
    3. "Id": 48,
    4. "Name": "初中",
    5. "AliasName": "",
    6. "ParentId": 5,
    7. "CoverUrl": null,
    8. "Children": [
    9. {
    10. "Id": 50,
    11. "Name": "数学",
    12. "AliasName": "",
    13. "ParentId": 48,
    14. "CoverUrl": null,
    15. "Children": [
    16. {
    17. "Id": 134,
    18. "Name": "版本",
    19. "AliasName": "",
    20. "ParentId": 50,
    21. "CoverUrl": null,
    22. "Children": [
    23. {
    24. "Id": 135,
    25. "Name": "人教版",
    26. "AliasName": "",
    27. "ParentId": 134,
    28. "CoverUrl": null,
    29. "Children": [
    30. {
    31. "Id": 141,
    32. "Name": "年级",
    33. "AliasName": "",
    34. "ParentId": 135,
    35. "CoverUrl": null,
    36. "Children": [
    37. {
    38. "Id": 142,
    39. "Name": "七年级上",
    40. "AliasName": "",
    41. "ParentId": 141,
    42. "CoverUrl": null,
    43. "Children": [
    44. {
    45. "Id": 148,
    46. "Name": "每章",
    47. "AliasName": "",
    48. "ParentId": 142,
    49. "CoverUrl": null,
    50. "Children": [
    51. {
    52. "Id": 149,
    53. "Name": "第一章",
    54. "AliasName": "",
    55. "ParentId": 148,
    56. "CoverUrl": null,
    57. "Children": [
    58. {
    59. "Id": 152,
    60. "Name": "每节",
    61. "AliasName": "",
    62. "ParentId": 149,
    63. "CoverUrl": null,
    64. "Children": [
    65. {
    66. "Id": 181,
    67. "Name": "第一节 函数、分数、负数",
    68. "AliasName": "",
    69. "ParentId": 152,
    70. "CoverUrl": null,
    71. "Children": null
    72. },
    73. {
    74. "Id": 182,
    75. "Name": "第二节 运算",
    76. "AliasName": "",
    77. "ParentId": 152,
    78. "CoverUrl": null,
    79. "Children": null
    80. }
    81. ]
    82. }
    83. ]
    84. },
    85. {
    86. "Id": 150,
    87. "Name": "第二章",
    88. "AliasName": "",
    89. "ParentId": 148,
    90. "CoverUrl": null,
    91. "Children": null
    92. },
    93. {
    94. "Id": 151,
    95. "Name": "第三章",
    96. "AliasName": "",
    97. "ParentId": 148,
    98. "CoverUrl": null,
    99. "Children": null
    100. }
    101. ]
    102. }
    103. ]
    104. },
    105. {
    106. "Id": 143,
    107. "Name": "七年级下",
    108. "AliasName": "",
    109. "ParentId": 141,
    110. "CoverUrl": null,
    111. "Children": null
    112. },
    113. {
    114. "Id": 144,
    115. "Name": "八年级上",
    116. "AliasName": "",
    117. "ParentId": 141,
    118. "CoverUrl": null,
    119. "Children": null
    120. },
    121. {
    122. "Id": 145,
    123. "Name": "八年级下",
    124. "AliasName": "",
    125. "ParentId": 141,
    126. "CoverUrl": null,
    127. "Children": null
    128. },
    129. {
    130. "Id": 146,
    131. "Name": "九年级上",
    132. "AliasName": "",
    133. "ParentId": 141,
    134. "CoverUrl": null,
    135. "Children": null
    136. },
    137. {
    138. "Id": 147,
    139. "Name": "九年级下",
    140. "AliasName": "",
    141. "ParentId": 141,
    142. "CoverUrl": null,
    143. "Children": null
    144. }
    145. ]
    146. }
    147. ]
    148. },
    149. {
    150. "Id": 136,
    151. "Name": "北师大版",
    152. "AliasName": "",
    153. "ParentId": 134,
    154. "CoverUrl": null,
    155. "Children": [
    156. {
    157. "Id": 183,
    158. "Name": "年级",
    159. "AliasName": "",
    160. "ParentId": 136,
    161. "CoverUrl": null,
    162. "Children": [
    163. {
    164. "Id": 162,
    165. "Name": "七年级上册",
    166. "AliasName": "",
    167. "ParentId": 183,
    168. "CoverUrl": null,
    169. "Children": [
    170. {
    171. "Id": 168,
    172. "Name": "每章",
    173. "AliasName": "",
    174. "ParentId": 162,
    175. "CoverUrl": null,
    176. "Children": [
    177. {
    178. "Id": 169,
    179. "Name": "第一章 丰富的图形世界",
    180. "AliasName": "",
    181. "ParentId": 168,
    182. "CoverUrl": null,
    183. "Children": [
    184. {
    185. "Id": 176,
    186. "Name": "知识点",
    187. "AliasName": "",
    188. "ParentId": 169,
    189. "CoverUrl": null,
    190. "Children": [
    191. {
    192. "Id": 177,
    193. "Name": "生活中的立体图形",
    194. "AliasName": "",
    195. "ParentId": 176,
    196. "CoverUrl": null,
    197. "Children": null
    198. },
    199. {
    200. "Id": 178,
    201. "Name": "展开与折叠",
    202. "AliasName": "",
    203. "ParentId": 176,
    204. "CoverUrl": null,
    205. "Children": null
    206. }
    207. ]
    208. }
    209. ]
    210. },
    211. {
    212. "Id": 170,
    213. "Name": "第二章 有理数及其运算",
    214. "AliasName": "",
    215. "ParentId": 168,
    216. "CoverUrl": null,
    217. "Children": null
    218. },
    219. {
    220. "Id": 171,
    221. "Name": "第三章 整式及其加减",
    222. "AliasName": "",
    223. "ParentId": 168,
    224. "CoverUrl": null,
    225. "Children": null
    226. },
    227. {
    228. "Id": 172,
    229. "Name": "第四章 基本平面图形",
    230. "AliasName": "",
    231. "ParentId": 168,
    232. "CoverUrl": null,
    233. "Children": null
    234. },
    235. {
    236. "Id": 173,
    237. "Name": "第五章 一元一次方程",
    238. "AliasName": "",
    239. "ParentId": 168,
    240. "CoverUrl": null,
    241. "Children": null
    242. },
    243. {
    244. "Id": 174,
    245. "Name": "第六章 数据的收集与整理",
    246. "AliasName": "",
    247. "ParentId": 168,
    248. "CoverUrl": null,
    249. "Children": null
    250. },
    251. {
    252. "Id": 175,
    253. "Name": "综合复习与测试",
    254. "AliasName": "",
    255. "ParentId": 168,
    256. "CoverUrl": null,
    257. "Children": null
    258. }
    259. ]
    260. }
    261. ]
    262. },
    263. {
    264. "Id": 163,
    265. "Name": "七年级下册",
    266. "AliasName": "",
    267. "ParentId": 183,
    268. "CoverUrl": null,
    269. "Children": null
    270. },
    271. {
    272. "Id": 164,
    273. "Name": "八年级上册",
    274. "AliasName": "",
    275. "ParentId": 183,
    276. "CoverUrl": null,
    277. "Children": null
    278. },
    279. {
    280. "Id": 165,
    281. "Name": "八年级下册",
    282. "AliasName": "",
    283. "ParentId": 183,
    284. "CoverUrl": null,
    285. "Children": null
    286. },
    287. {
    288. "Id": 166,
    289. "Name": "九年级上册",
    290. "AliasName": "",
    291. "ParentId": 183,
    292. "CoverUrl": null,
    293. "Children": null
    294. },
    295. {
    296. "Id": 167,
    297. "Name": "九年级下册",
    298. "AliasName": "",
    299. "ParentId": 183,
    300. "CoverUrl": null,
    301. "Children": null
    302. }
    303. ]
    304. }
    305. ]
    306. },
    307. {
    308. "Id": 137,
    309. "Name": "苏科版",
    310. "AliasName": "",
    311. "ParentId": 134,
    312. "CoverUrl": null,
    313. "Children": null
    314. },
    315. {
    316. "Id": 138,
    317. "Name": "沪科版(2012)",
    318. "AliasName": "",
    319. "ParentId": 134,
    320. "CoverUrl": null,
    321. "Children": null
    322. },
    323. {
    324. "Id": 139,
    325. "Name": "华东师大版(2012)",
    326. "AliasName": "",
    327. "ParentId": 134,
    328. "CoverUrl": null,
    329. "Children": null
    330. },
    331. {
    332. "Id": 140,
    333. "Name": "浙教版(2012)",
    334. "AliasName": "",
    335. "ParentId": 134,
    336. "CoverUrl": null,
    337. "Children": null
    338. },
    339. {
    340. "Id": 155,
    341. "Name": "冀教版(2012)",
    342. "AliasName": "",
    343. "ParentId": 134,
    344. "CoverUrl": null,
    345. "Children": null
    346. },
    347. {
    348. "Id": 156,
    349. "Name": "青岛版(2012)",
    350. "AliasName": "",
    351. "ParentId": 134,
    352. "CoverUrl": null,
    353. "Children": null
    354. },
    355. {
    356. "Id": 157,
    357. "Name": "鲁教版(五四制)(2012)",
    358. "AliasName": "",
    359. "ParentId": 134,
    360. "CoverUrl": null,
    361. "Children": null
    362. },
    363. {
    364. "Id": 158,
    365. "Name": "人教版(五四制)",
    366. "AliasName": "",
    367. "ParentId": 134,
    368. "CoverUrl": null,
    369. "Children": null
    370. },
    371. {
    372. "Id": 159,
    373. "Name": "京改版",
    374. "AliasName": "",
    375. "ParentId": 134,
    376. "CoverUrl": null,
    377. "Children": null
    378. },
    379. {
    380. "Id": 160,
    381. "Name": "沪教版(上海)",
    382. "AliasName": "",
    383. "ParentId": 134,
    384. "CoverUrl": null,
    385. "Children": null
    386. },
    387. {
    388. "Id": 161,
    389. "Name": "湘教版(2012)",
    390. "AliasName": "",
    391. "ParentId": 134,
    392. "CoverUrl": null,
    393. "Children": null
    394. }
    395. ]
    396. }
    397. ]
    398. },
    399. {
    400. "Id": 51,
    401. "Name": "语文",
    402. "AliasName": "",
    403. "ParentId": 48,
    404. "CoverUrl": null,
    405. "Children": null
    406. },
    407. {
    408. "Id": 52,
    409. "Name": "英语",
    410. "AliasName": "",
    411. "ParentId": 48,
    412. "CoverUrl": null,
    413. "Children": null
    414. },
    415. {
    416. "Id": 53,
    417. "Name": "物理",
    418. "AliasName": "",
    419. "ParentId": 48,
    420. "CoverUrl": null,
    421. "Children": null
    422. },
    423. {
    424. "Id": 54,
    425. "Name": "化学",
    426. "AliasName": "",
    427. "ParentId": 48,
    428. "CoverUrl": null,
    429. "Children": null
    430. },
    431. {
    432. "Id": 55,
    433. "Name": "生物",
    434. "AliasName": "",
    435. "ParentId": 48,
    436. "CoverUrl": null,
    437. "Children": null
    438. },
    439. {
    440. "Id": 56,
    441. "Name": "政治",
    442. "AliasName": "",
    443. "ParentId": 48,
    444. "CoverUrl": null,
    445. "Children": null
    446. }
    447. ]
    448. },
    449. {
    450. "Id": 49,
    451. "Name": "高中",
    452. "AliasName": "",
    453. "ParentId": 5,
    454. "CoverUrl": null,
    455. "Children": null
    456. }
    457. ]

    三、组件的封装,以下三个vue页面文件组件,组合成了筛选页

    1、分析

    根据设计图需求以及数据结构的结合,返回的数据结构形成的深层嵌套循环与布局不符,其中Children下的数组,数组下的Children是不确定到底有多少层级的,因此

    (1)如果直接循环渲染,页面是还原不了设计图的(无论多少层级,都要求左对齐

    (2)如果通过定位的方式布局,就直接写死了(行不通)

    2、针对 问题(1) 采取的方法

    (1)将右侧筛选弹窗的内容封装成小的组件 menuTree1.vue (也是最里层),如下图

    menuTree1.vue

    1. <template>
    2. <div class="r_item" :style="'width:100%;margin-left:' + (prs.index > 0 ? -prs.width : 0) + 'px'"
    3. v-for="(right,riIndex) in menuList" :key="riIndex">
    4. <div style="display:flex;" v-if="right.Children &&right.Children.length>0">
    5. <div class="r_item_title" :data-index="right.Id">{{ right.Name }}></div>
    6. <div class="r_nav" v-if="right.Children && right.Children.length > 0">
    7. <div class="r_nav_item" v-for="(chi, chiIndex) in right.Children" :key="chiIndex"
    8. :class="`${person.menuActive == chi.Id ? 'r_nav_item_active' : ''} ${right.Children.length === 1 ?'r_nav2':''}`"
    9. @click="goPage(chi.Children, chi.Id, right.Id, chiIndex)">
    10. {{ chi.Name }}
    11. </div>
    12. <menuTree v-if="person.isChild && person.isChild[0].ParentId == person.ClickId && right.Id == person.Pid"
    13. :menuList="person.isChild" :width="person.width" :Id="person.ClickId" :index="1" @MenuTree1="MenuTree1">
    14. </menuTree>
    15. </div>
    16. </div>
    17. </div>
    18. </template>
    19. <script setup lang="ts">
    20. import menuTree from './menuTree1.vue';
    21. import { nextTick, onMounted, reactive, ref, toRaw } from 'vue';
    22. let person: any = reactive({
    23. IsChild: [],
    24. ClickId: 0,
    25. Pid: 0,
    26. index: 0,
    27. width: 0,
    28. menuActive:-1,
    29. cwidth:0
    30. })
    31. type Menu = {
    32. Name: string,
    33. Children?: Menu[],
    34. ParentId: number,
    35. Id: number
    36. }
    37. const isChild = ref()
    38. type Props = {
    39. menuList: Menu[],
    40. index: number,
    41. width:number,
    42. Id:number
    43. }
    44. var prop = defineProps<Props>()
    45. let prs = toRaw(prop)
    46. const emits = defineEmits(['MenuTree1']);
    47. const goPage = (data: Menu[], Id: number, Pid: number,index:number) => {
    48. person.menuActive = Id
    49. person.isChild = data
    50. person.ClickId = Id
    51. person.Pid = Pid
    52. person.index = person.index + 1
    53. var a = document.getElementsByClassName('r_item_title')
    54. for (let index = 0; index < a.length; index++) {
    55. const element = a[index];
    56. var di = element.getAttribute('data-index')
    57. if (Number(di) === Pid) {
    58. // person.width = element.scrollWidth // + 15
    59. // 获取元素
    60. let secMargin = getComputedStyle(element);
    61. person.width = element.scrollWidth + parseFloat(secMargin.marginRight.replace('px', ''))
    62. break;
    63. }
    64. }
    65. emits('MenuTree1', Id);
    66. };
    67. const MenuTree1 = (Id: number) => {
    68. emits('MenuTree1', Id);
    69. }
    70. onMounted(()=>{
    71. nextTick(()=>{
    72. person.cwidth = document.body.scrollWidth
    73. window.onresize=()=>{
    74. var a = document.getElementsByClassName('r_item_title')[0]
    75. let secMargin = getComputedStyle(a);
    76. var w = a.scrollWidth + parseFloat(secMargin.marginRight.replace('px', ''))
    77. //获取所有的r_item 元素
    78. var r_item = document.getElementsByClassName('r_item')
    79. for (let index = 0; index < r_item.length; index++) {
    80. const element = r_item[index];
    81. //判断是否存在margin-left
    82. let elementSecMargin = getComputedStyle(element);
    83. var i = elementSecMargin.marginLeft.replace('px', '')
    84. if (parseInt(i)<0){
    85. element.style.marginLeft = -w + "px"
    86. }
    87. }
    88. }
    89. })
    90. })
    91. </script>

    (2)再将 menuTree1.vue 引入 封装的第二层组件 menuTree.vue 循环调用

    menuTree.vue

    1. <template>
    2. <div class="r_item" :style="'width:100%;'" v-for="(right,riIndex) in menuList" :key="riIndex">
    3. <div style="display:flex;">
    4. <div class="r_item_title" :data-index="right.Id">{{ right.Name }}></div>
    5. <div class="r_nav" v-if="right.Children && right.Children.length>0">
    6. <div class="r_nav_item" :class="person.menuActive == chi.Id ?'r_nav_item_active':''" v-for="(chi,chiIndex) in right.Children" :key="chiIndex" @click="goPage(chi.Children, chi.Id, right.Id, chiIndex)">
    7. {{ chi.Name }}
    8. </div>
    9. <menuTree v-if="person.isChild && person.isChild[0].ParentId == person.ClickId && right.Id==person.Pid" :width="person.width" :menuList="person.isChild" :index="1"
    10. :Id="0" @MenuTree1="MenuTree1">
    11. </menuTree>
    12. </div>
    13. </div>
    14. </div>
    15. </template>
    16. <script setup lang="ts">
    17. import menuTree from './menuTree1.vue';
    18. import { reactive, ref, toRaw } from 'vue';
    19. let person: any = reactive({
    20. IsChild:[],
    21. ClickId:0,
    22. Pid:0,
    23. index:0,
    24. width:0,
    25. menuActive:-1
    26. })
    27. type Menu = {
    28. Name: string,
    29. Children?: Menu[],
    30. ParentId: number,
    31. Id: number
    32. }
    33. const isChild = ref()
    34. type Props = {
    35. menuList: Menu[],
    36. index:number
    37. }
    38. var prop= defineProps<Props>()
    39. let prs = toRaw(prop)
    40. const emits = defineEmits(['MenuTree']);
    41. const goPage = (data:Menu[],Id:number,Pid:number,index:number) => {
    42. person.menuActive = Id
    43. person.isChild=data
    44. person.ClickId=Id
    45. person.Pid=Pid
    46. person.index=person.index+1
    47. var a= document.getElementsByClassName('r_item_title')
    48. for (let index = 0; index < a.length; index++) {
    49. const element = a[index];
    50. var di = element.getAttribute('data-index')
    51. if (Number(di) === Pid) {
    52. // person.width = element.scrollWidth // + 15
    53. // 获取元素
    54. let secMargin = getComputedStyle(element);
    55. // console.log('获取值', secMargin.marginRight);
    56. person.width = element.scrollWidth +parseFloat(secMargin.marginRight.replace('px',''))
    57. break;
    58. }
    59. }
    60. MenuTree1(person.ClickId)
    61. };
    62. // // 获取里层的方法
    63. const MenuTree1 =(item:any)=>{
    64. emits('MenuTree', item);
    65. }
    66. </script>

    (3)再将 menuTree.vue 引入 封装的第一层组件 index.vue 调用,如下图

    index.vue

    1. <template>
    2. <div class="screen_page" v-if="person.gradeList && person.gradeList.length>0">
    3. <div class="screen_l">
    4. <!-- 年级 -->
    5. <div class="l_nav">
    6. <div class="l_nav_item" :class="[person.gradeActive===grIndex?'l_nav_item_active':'']" v-for="(grade,grIndex) in person.gradeList" :key="grIndex" @click="gradeChange(grade, grIndex)">
    7. {{ grade.Name }}
    8. </div>
    9. </div>
    10. <!-- 科目 -->
    11. <div class="l_nav_panel" v-if="person.gradeList[person.gradeActive].Children && person.gradeList[person.gradeActive].Children.length > 0">
    12. <div class="panel_item" :class="[person.subjectActive === chiIndex ?'panel_item_active':'']" v-for="(chi,chiIndex) in person.gradeList[person.gradeActive].Children" :key="chiIndex" @click="subjectChange(chi, chiIndex)">
    13. <span>{{ chi.Name }}</span>
    14. <i class="el-icon-caret-right"></i>
    15. </div>
    16. </div>
    17. <div v-else class="null_box">
    18. <p>暂无科目</p>
    19. </div>
    20. </div>
    21. <!-- 右侧 -->
    22. <div class="screen_r" v-if="person.isShowRight">
    23. <div class="r_item_socrll" v-if="person.rightList && person.rightList.length>0">
    24. <div class="r_item_box">
    25. <menuTree :menuList="person.rightList" @MenuTree="MenuTree" ></menuTree>
    26. </div>
    27. </div>
    28. <div v-else class="null_box">
    29. <p>暂无筛选数据</p>
    30. </div>
    31. <div class="r_btn">
    32. <el-button @click="okClick">确定</el-button>
    33. <el-button @click="cancelClick">取消</el-button>
    34. </div>
    35. </div>
    36. </div>
    37. </template>
    38. <script lang="ts" setup>
    39. import { reactive, defineExpose, toRaw, ref } from 'vue'
    40. import menuTree from './menuTree.vue';
    41. let person: any = reactive({
    42. gradeList:[], // 年级及以下列表
    43. gradeActive: 0, // 年级筛选
    44. subjectActive: -1, // 科目筛选
    45. isShowRight:false, // 是否显示右侧
    46. rightList: [], // 右侧一级列表
    47. rightId:0,
    48. lastId:0
    49. })
    50. type TleftData={
    51. AliasName: string,
    52. Children: Array<TleftData>
    53. CoverUrl: string
    54. Id: string
    55. Name: string
    56. }
    57. type TProps = {
    58. leftData: Array<TleftData>
    59. }
    60. let prop = defineProps<TProps>()
    61. let prs = toRaw(prop)
    62. person.gradeList = prs.leftData
    63. const emit = defineEmits(['gradeMenu', 'okMenu'])
    64. // 年级切换
    65. const gradeChange=(item:any,index:number)=>{
    66. person.gradeActive = index
    67. emit('gradeMenu', item)
    68. }
    69. // 科目切换
    70. const subjectChange = (item: any, index: number) => {
    71. person.subjectActive = index
    72. person.isShowRight=true
    73. if (item.Children && item.Children.length > 0){
    74. person.rightList = item.Children
    75. person.rightId=item.Id
    76. }else{
    77. person.rightList = []
    78. }
    79. }
    80. const MenuTree = (Id: number) => {
    81. console.log('点击完成后', Id)
    82. person.lastId = Id
    83. };
    84. // 确认筛选
    85. const okClick=()=>{
    86. person.isShowRight = false
    87. let selectId = 0
    88. const gradeId = person.gradeList[person.gradeActive].Id
    89. const subjectId = person.gradeList[person.gradeActive].Children[person.subjectActive] && person.gradeList[person.gradeActive].Children[person.subjectActive].Id
    90. if (person.lastId>0){
    91. selectId = person.lastId
    92. } else if (subjectId>0){
    93. selectId = subjectId
    94. } else if (gradeId > 0) {
    95. selectId = gradeId
    96. }
    97. emit('okMenu', selectId)
    98. person.lastId = 0
    99. }
    100. // 取消筛选
    101. const cancelClick = () => {
    102. person.isShowRight = false
    103. }
    104. </script>
    105. <style lang="scss">
    106. .r_nav {
    107. display: flex;
    108. flex-wrap: wrap;
    109. color: #737272;
    110. font-size: 16px;
    111. .r_nav_item {
    112. margin-right: 20px;
    113. margin-bottom: 10px;
    114. }
    115. .r_nav_item_active {
    116. color: #5182FF;
    117. }
    118. }
    119. .r_nav1 {
    120. white-space: normal !important;
    121. display: flex;
    122. flex-wrap: wrap;
    123. justify-content: start;
    124. color: #737272;
    125. height: auto !important;
    126. .r_nav_item1 {
    127. margin-right: 20px;
    128. margin-bottom: 15px;
    129. }
    130. .r_nav_item1_active {
    131. color: #5182FF;
    132. border: 1px solid #5182FF;
    133. }
    134. }
    135. .r_nav2{
    136. max-width: 450px;
    137. min-width: 350px;
    138. }
    139. .r_item {
    140. padding: 15px 0;
    141. .r_item_title {
    142. font-weight: 500;
    143. margin-right: 15px;
    144. color: #000;
    145. font-size: 16px;
    146. }
    147. }
    148. </style>
    149. <style lang="scss" scoped >
    150. .screen_page {
    151. width: 1200px;
    152. height: calc(100vh - 200px);
    153. display: flex;
    154. position: relative;
    155. .screen_l{
    156. width: 257px;
    157. padding: 15px;
    158. font-size: 16px;
    159. color: #6D6D6D;
    160. background: #fff;
    161. .l_nav{
    162. display: flex;
    163. justify-content: space-between;
    164. .l_nav_item{
    165. padding: 5px 0px;
    166. border: 1px solid #5182FF;
    167. border-radius: 4px;
    168. color: #5182FF;
    169. width: 50%;
    170. text-align: center;
    171. margin-right: 10px;
    172. }
    173. .l_nav_item:last-child{
    174. margin-right: 2px;
    175. }
    176. .l_nav_item_active{
    177. color: #fff !important;
    178. background: #5182FF !important;
    179. }
    180. }
    181. .l_nav_panel::-webkit-scrollbar {
    182. width: 4px;
    183. }
    184. .l_nav_panel::-webkit-scrollbar-thumb{
    185. background: #eee;
    186. border-radius: 10px;
    187. }
    188. .l_nav_panel{
    189. margin-top: 15px;
    190. height: calc(100vh - 290px);
    191. overflow-y: scroll;
    192. .panel_item{
    193. border-radius: 4px;
    194. padding: 10px 5px 10px 10px;
    195. display: flex;
    196. justify-content: space-between;
    197. i{
    198. color: #D9E4FF;
    199. font-size: 20px;
    200. }
    201. }
    202. .panel_item_active{
    203. background: rgba(81, 130, 255, 0.15);
    204. color: #5182FF;
    205. i {
    206. color: #5182FF;
    207. }
    208. }
    209. }
    210. }
    211. .screen_r{
    212. border-left: 1px solid #D7D7D7;
    213. white-space: nowrap;
    214. width: calc(100% - 257px);
    215. z-index: 100000;
    216. background: #fff;
    217. padding: 20px 60px 20px 30px;
    218. position: relative;
    219. .r_item_socrll::-webkit-scrollbar{
    220. width: 0;
    221. }
    222. .r_item_socrll{
    223. border-bottom: 1px solid #EAEAEA;
    224. height: calc(100% - 80px);
    225. overflow-y: scroll;
    226. .r_item_box {
    227. border-bottom: 1px solid #EAEAEA;
    228. }
    229. .r_item_box:last-child {
    230. border:0;
    231. }
    232. .r_item:last-child{
    233. border: 0;
    234. }
    235. }
    236. .r_btn{
    237. position: absolute;
    238. bottom: 40px;
    239. right: 90px;
    240. .el-button{
    241. min-height: inherit;
    242. padding: 9px 32px;
    243. }
    244. .el-button:first-child{
    245. background: #5182FF;
    246. color: #fff;
    247. }
    248. .el-button:nth-child(2) {
    249. border: 1px solid #5182FF;
    250. color:#5182FF;
    251. }
    252. }
    253. }
    254. }
    255. </style>

    四、课程列表页中的调用

    1. // 页面使用
    2. <template>
    3. <div>
    4. <Screen @gradeMenu="gradeMenu" @okMenu="okMenu" v-if="person.menuList && person.menuList.length > 0" :leftData="person.menuList"></Screen>
    5. </div>
    6. </template>
    7. // 引入组件
    8. <script lang="ts" setup>
    9. import Screen from "@/components/Screen/index.vue";
    10. // 年级切换
    11. const gradeMenu = (item: any) => {
    12. // 获取传递过来的Id
    13. console.log(item.Id)
    14. }
    15. // 确认筛选
    16. const okMenu = (lastId: number) => {
    17. // 获取筛选后点击确认传递过来的Id
    18. console.log(lastId)
    19. }
    20. </script>

           希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

  • 相关阅读:
    dubbo功能非常完善,好用的功能你又知道哪些?
    使用ClickHouse JDBC官方驱动,踩坑无数
    在C#中进行单元测试
    【代码随想录】二刷-二叉树
    编程基础知识编程实例解析:深度探索与实战应用
    红队打靶:Fowsniff打靶思路详解(vulnhub)
    k8s-NFS系统配置
    企业网络革命:连接和访问的智慧选项
    【springboot+vue项目学习】Unable to start web server引发的问题串
    路由不变,页面刷新
  • 原文地址:https://blog.csdn.net/weixin_50450473/article/details/127665321