国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Vue列表如何實現滾動到指定位置樣式改變效果

瀏覽:5日期:2023-01-22 10:30:02

這個需求大概是這樣子:

我做的一個聊天Demo,在搜索框搜索用戶,可以滾動到指定的用戶。然后成選中狀態。

這是目前狀態,我搜索南宮仆射 ,想要下面的用戶列表直接滾動到南宮仆射并改變CSS樣式。

Vue列表如何實現滾動到指定位置樣式改變效果

查詢之后是這個子:

Vue列表如何實現滾動到指定位置樣式改變效果

嗯,我的思路:

在搜索框搜索到用戶之后會返回一個用戶對象,之后會調用列表的點擊事件,改變CSS樣式及做一些聊天的邏輯。然后需要獲取到列表對應的id值,直接使用 document.getElementById(it).scrollIntoView();

具體實現:

列表:使用vue的v-for指令 ,這里的id值使用的是遍歷的索引值,外層是一個自定義滾動條組件。樣式也是使用vue指令,一個語法糖。

<GeminiScrollbar class='my-scroll-bars'> <li v-for='(item,index) in hrs' ::key='index' :@click='changeCurrentSession(item)'> <img :src='http://m.cgvv.com.cn/bcjs/item.userface'> <el-badge :is-dot='isDot[user.username+’#’+item.username]'><p class='name'>{{item.name}}</p> </el-badge> </li> </GeminiScrollbar>

搜索框:這里使用帶提示的輸入框,

<el-autocomplete v-model='SearchHr' popper-append-to-body='false' size='small' :fetch-suggestions='querySearch' placeholder='請輸入內容' @select='handleSelect' > <el-button slot='append' icon='el-icon-search' @click='SearchCurrentSession(SearchHr)'></el-button> </el-autocomplete>

JS代碼:請求為get請求的axios封裝,hr為查詢返回的對象,hrs為所有的列表對象。

SearchCurrentSession() { this.getRequest('/chat/?name=' + this.SearchHr).then(resp => { if (resp) { this.hr = resp; this.SearchHr = ’’; this.changeCurrentSession(this.hr); let it = 0; this.hrs.forEach((item, index) => { if (item.name == this.hr.name) {it = index; } }) document.getElementById(it).scrollIntoView(); // document.getElementsByClassName('active')[0].scrollIntoView(); } });

changeCurrentSession(currentSession) { this.$store.commit(’changeCurrentSession’, currentSession) },

頁面全部代碼:

<template> <div style='display: flex;justify-content:space-between;height: 100%;width: 100%'> <div class='leftlist'> <el-menu background-color='#2e3238' router active-text-color='#67C23A' text-color='#fff' :collapse='isCollapse'> <el-menu-item index='/chat' style='padding-left: 10px;margin:10px 0px 20px 2px'> <el-tooltip effect='light' placement='right-start' popper-class='el-scrollbar'> <div slot='content'> <div style='margin-top: 5px;font-size: 13px;lineHeight:1.5;'><div>用戶名:{{user.name}}</div><div>手機號碼:{{user.phone}}</div><div>電話號碼:{{user.telephone}}</div><div>地 址:{{user.address}}</div><div>備注:{{user.remark}}</div> </div> </div> <img :src='http://m.cgvv.com.cn/bcjs/user.userface':alt='user.name'></el-tooltip> </el-menu-item> <el-menu-item index='/chat' style='padding-left: 15px'> <i class='fa fa-weixin fa-2x'></i> </el-menu-item> <el-menu-item index='/chat' style='padding-left: 15px'> <i class='fa fa-windows fa-2x'></i> </el-menu-item> <el-menu-item index='/chat' style='padding-left: 15px'> <i class='fa fa-modx fa-2x'></i> </el-menu-item> <el-menu-item index='/chat' style='padding-left: 15px'> <i class='fa fa-share-alt fa-2x'></i> </el-menu-item> </el-menu> </div> <div id='list'> <div style='height:100%;width:100%;overflow-x: hidden'> <ul style='padding-left: 0px; overflow-x: hidden;'> <el-autocomplete v-model='SearchHr' popper-append-to-body='false' size='small' :fetch-suggestions='querySearch' placeholder='請輸入內容' @select='handleSelect' > <el-button slot='append' icon='el-icon-search' @click='SearchCurrentSession(SearchHr)'></el-button> </el-autocomplete> <GeminiScrollbar class='my-scroll-bars'> <li v-for='(item,index) in hrs' ::key='index' :@click='changeCurrentSession(item)'> <img :src='http://m.cgvv.com.cn/bcjs/item.userface'> <el-badge :is-dot='isDot[user.username+’#’+item.username]'><p class='name'>{{item.name}}</p> </el-badge> </li> </GeminiScrollbar> </ul> </div> </div> </div></template><script> import {mapState} from ’vuex’ export default { name: ’list’, data() { return { isCollapse: true, SearchHr: ’’, hr: '', restaurants: [], user: JSON.parse(window.sessionStorage.getItem('user')) } }, computed: { ...mapState([ ’hrs’, ’isDot’, ’currentSession’ ]) }, methods: { SearchCurrentSession() { this.getRequest('/chat/?name=' + this.SearchHr).then(resp => { if (resp) { this.hr = resp; this.SearchHr = ’’; this.changeCurrentSession(this.hr); let it = 0; this.hrs.forEach((item, index) => { if (item.name == this.hr.name) {it = index; } }) document.getElementById(it).scrollIntoView(); // document.getElementsByClassName('active')[0].scrollIntoView(); } }); }, querySearch(queryString, cb) { this.restaurants = this.loadAll(); let restaurants = []; this.restaurants.forEach(value => { let {name, username} = value; let restaurant = {value: name, username: username} restaurants.push(restaurant); }); var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants; // 調用 callback 返回建議列表的數據 cb(results); }, createFilter(queryString) { return (SearchHr) => { return (SearchHr.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0); }; }, loadAll() { return this.hrs; }, changeCurrentSession(currentSession) { this.$store.commit(’changeCurrentSession’, currentSession) }, handleSelect(item) { console.log(item); } }, mounted() { this.$store.dispatch(’initData’); } }</script><style lang='scss' scoped> .my-scroll-bars { height: 610px; } /* override gemini-scrollbar default styles */ /* vertical scrollbar track */ .gm-scrollbar.-vertical { background-color: #f0f0f0 } /* horizontal scrollbar track */ .gm-scrollbar.-horizontal { background-color: transparent; } /* scrollbar thumb */ .gm-scrollbar .thumb { background-color: rebeccapurple; } .gm-scroll-view { overflow-x: hidden; } .gm-scrollbar .thumb:hover { background-color: fuchsia; } input-with-select { margin-top: 50px; padding-top: 20px; } .el-scrollbar__wrap { width: 100%; height: 100%; overflow-x: hidden; } .el-menu-item is-active { padding-left: 10px; } .el-menu-vertical-demo { background-color: #2e3238; width: 80px; height: 100%; /*opacity:0.8;*/ } .leftlist { background-color: transparent; width: 90px; height: 700px; overflow-x: hidden; } .avatar { width: 45px; height: 45px; /*這個是圖片和文字居中對齊*/ border-radius: 5px; margin-top: 5px; } .el-scrollbar__wrap { background-color: #E4E7ED; } #el-scrollbar { background-color: #E4E7ED; } #list { background-color: #E4E7ED; width: 100%; overflow-x: hidden; li { padding: 7px 15px; border-bottom: 1px solid #E4E7ED; cursor: pointer; list-style: none; color: #505458; &:hover { background-color: rgba(0, 0, 0, 0.07); } } li.active { /*注意這個是.不是冒號:*/ background-color: rgba(0, 0, 0, 0.1); } .avatar { border-radius: 2px; width: 30px; height: 30px; vertical-align: middle; } .name { display: inline-block; margin-left: 15px; margin-top: 0px; margin-bottom: 0px; } }</style>

總結

到此這篇關于Vue列表實現滾動到指定位置樣式改變的文章就介紹到這了,更多相關Vue列表實現滾動到指定位置樣式改變內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Vue
相關文章:
主站蜘蛛池模板: 男女在线免费视频 | 欧美午夜在线观看理论片 | 午夜免费一级片 | 国产精品91在线 | 日韩久久久精品中文字幕 | 国产精品反差婊在线观看 | 欧美在线观看成人高清视频 | 国产人成久久久精品 | 九九毛片| 中文一区二区在线观看 | 日本一级特黄特色大片免费视频 | 九九久久免费视频 | 国产主播福利片在线观看 | 日韩美女网站在线看 | 久久一本色系列综合色 | 中国老太性色xxxxxhd | 亚欧成人一区二区 | 久久亚洲国产精品五月天 | 欧美一级高清在线观看 | 毛片毛片毛是个毛毛片 | 日本尹人综合香蕉在线观看 | 国产精品区在线12p 国产精品人成 | 一级片aaaa| 日本理论片午夜论片 | 亚洲性免费| 久久精品国产只有精品6 | 亚洲无线一二三区2021 | 久久高清一级毛片 | 亚洲精品国产第一区二区多人 | 亚洲九九香蕉 | 欧美成人午夜 | 欧美色久| 国产真实孩交 | 亚洲 欧美 精品 中文第三 | 萌白酱白丝护士服喷水铁牛tv | 美女张开腿让男人捅的视频 | 国产乱肥老妇精品视频 | 亚洲精品欧美 | 久久久这里只有精品免费 | 国产精品一级 | 窝窝人体色 |