最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mpvue實現(xiàn)左側(cè)導(dǎo)航與右側(cè)內(nèi)容的聯(lián)動

 更新時間:2019年10月21日 09:58:54   作者:yumihe  
這篇文章主要為大家詳細(xì)介紹了mpvue實現(xiàn)左側(cè)導(dǎo)航與右側(cè)內(nèi)容的聯(lián)動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了mpvue左側(cè)導(dǎo)航與右側(cè)內(nèi)容聯(lián)動的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:

(1)左側(cè)導(dǎo)航聯(lián)動右側(cè)內(nèi)容

實現(xiàn):點擊左側(cè)導(dǎo)航,右側(cè)內(nèi)容滑到對應(yīng)的位置,并且導(dǎo)航上有current當(dāng)前樣式。

mpvue用的還是微信小程序提供的組件scroll-view,它里面有一個屬性scroll-into-view,值為某子元素的id,滾動到該元素。

template:

<scroll-view class="menu-wrapper" scroll-y>
 <ul>
 <li class="menu-item"
 v-for="(item,index) in goods"
 :class="index===currentIndex ? 'current' : ''"
 :key="index"
 @tap="selectMenu(index)">
  {{item.name}}
 </li>
 </ul>
</scroll-view>
<scroll-view scroll-y
  :scroll-into-view="contentId"
  scroll-with-animation="true"
  class="foods-wrapper">
 <ul>
 <li v-for="(item,i) in goods"
 :id="'con_'+i"
 class="food-list food-list-hook" :key="i">
 </li>
 </ul>
<scroll-view>

js:

data() {
 return {
 goods: [],
 contentId: '', // 每個food-list的id,scroll-into-view滾動到對應(yīng)的id
 currentIndex: 0
 }
},
methods: {
 selectMenu(index) {
 this.contentId = `con_${index}`
 this.currentIndex = index
 }
}

(2)在左側(cè)導(dǎo)航聯(lián)動右側(cè)內(nèi)容的基礎(chǔ)上增加右側(cè)內(nèi)容聯(lián)動左側(cè)導(dǎo)航

實現(xiàn):滑動右側(cè)內(nèi)容區(qū)域,給左側(cè)對應(yīng)導(dǎo)航增加current樣式,并且當(dāng)導(dǎo)航高度過長,會聯(lián)動其滾動

補充:contentHeight是右側(cè)內(nèi)容scroll-view的高度,同時也是左側(cè)導(dǎo)航scroll-view的高度,navItemHeight是導(dǎo)航ul下每一個item的高度,當(dāng)導(dǎo)航下ul的高度超過scroll-view的高度,并且this.currentIndex * this.navItemHeight  > this.contentHeight,導(dǎo)航才向上滾動。

tempate:

<scroll-view class="menu-wrapper"
  :scroll-into-view="navId"
  scroll-with-animation="true"
  scroll-y>
 <ul class="menu-ul">
 <li class="menu-item"
 v-for="(item,index) in goods"
 :id="'nav_'+index"
 :class="index===currentIndex ? 'current' : ''"
 :key="index"
 @tap="selectMenu(index)">
  {{item.name}}
 </li>
 </ul>
</scroll-view>
<scroll-view scroll-y
  @scroll="onScroll"
  :scroll-into-view="contentId"
  scroll-with-animation="true"
  class="foods-wrapper">
 <ul>
 <li v-for="(item,i) in goods"
 :id="'con_'+i"
 class="food-list food-list-hook" :key="i">
 </li>
 </ul>
</scroll-view>

js:

export default{
 data() {
 return {
 goods: [],
 contentId: '', // 每個food-list的id,scroll-into-view滾動到對應(yīng)的id
 navId: '', // 導(dǎo)航模塊對應(yīng)的id,用來聯(lián)動內(nèi)容區(qū)域
 currentIndex: 0,
 navulHeight: 0, // 導(dǎo)航里ul高度
 navItemHeight: 0, // 每個導(dǎo)航高度
 listHeight: [], // foods內(nèi)部塊的高度
 contentHeight: [], // 內(nèi)容區(qū)域scroll-view高度
 }
 },
 watch: {
 currentIndex() {
 console.log(this.currentIndex)
 if (this.contentHeight < this.navulHeight) {
 let h = this.currentIndex * this.navItemHeight
 if (h > this.contentHeight) {
  // 導(dǎo)航滑動
  this.navId = `nav_${this.currentIndex}`
 } else {
  this.navId = 'nav_0'
 }
 }
 }
 },
 methods: {
 selectMenu(index) {
 this.contentId = `con_${index}`
 this.navId = `nav_${index}`
 this.currentIndex = index
 },
 onScroll(e) {
 this.contentId = ''
 let scrollTop = e.target.scrollTop
 // console.log(scrollTop)
 let length = this.listHeight.length
 if (scrollTop >= this.listHeight[length - 1] - this.contentHeight) {
 return
 } else if (scrollTop > 0 && scrollTop < this.listHeight[0]) {
 this.currentIndex = 0
 }
 for (let i = 0; i < length; i++) {
 if (scrollTop >= this.listHeight[i - 1] && scrollTop < this.listHeight[i]) {
  this.currentIndex = i
 }
 }
 // console.log(this.currentIndex)
 },
 getFoodHeight() {
 var query = wx.createSelectorQuery()
 let h = 0
 query.selectAll('.food-list-hook').boundingClientRect((rects) => {
 // console.log(rects)
 rects.forEach((rect) => {
  h += rect.height
  this.listHeight.push(h)
 })
 // console.log(this.listHeight)
 })
 query.select('.foods-wrapper').boundingClientRect((rect) => {
 this.contentHeight = rect.height
 })
 query.select('.menu-ul').boundingClientRect((rect) => {
 this.navulHeight = rect.height
 })
 query.select('.menu-item').boundingClientRect((rect) => {
 this.navItemHeight = rect.height
 }).exec()
 }
 },
 watch: {
 goods() {
 // 獲取模塊高度,即food-list
 setTimeout(() => {
 this.getFoodHeight()
 }, 60)
 }
 }
}

更多教程點擊《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。

關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3組件更新中的DOM?diff算法示例詳解

    Vue3組件更新中的DOM?diff算法示例詳解

    虛擬dom是當(dāng)前前端最流行的兩個框架(vue和react)都用到的一種技術(shù),都說他能幫助vue和react提升渲染性能,提升用戶體驗,下面這篇文章主要給大家介紹了關(guān)于Vue3組件更新中的DOM?diff算法的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • vue封裝一個簡單的div框選時間的組件的方法

    vue封裝一個簡單的div框選時間的組件的方法

    這篇文章主要介紹了vue封裝一個簡單的div框選時間的組件的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • vue中 this.$set的使用詳解

    vue中 this.$set的使用詳解

    這篇文章主要為大家介紹了vue中 this.$set的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • Vue通過ref獲取不到$refs問題

    Vue通過ref獲取不到$refs問題

    這篇文章主要介紹了Vue通過ref獲取不到$refs問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • vue設(shè)置頁面超時15分鐘自動退出登錄的方法詳解

    vue設(shè)置頁面超時15分鐘自動退出登錄的方法詳解

    當(dāng)用戶登錄后,如果長時間未操作頁面這個時候需要自動退出登錄回到登錄頁面,本文將給大家介紹一下vue設(shè)置頁面超時15分鐘自動退出登錄的方法,感興趣的同學(xué)可以自己動手試一下
    2023-10-10
  • Vite多環(huán)境配置及變量識別規(guī)則

    Vite多環(huán)境配置及變量識別規(guī)則

    這篇文章主要為大家介紹了Vite多環(huán)境配置時間及vite識別環(huán)境變量的規(guī)則,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • vue3項目中引入ts的詳細(xì)圖文教程

    vue3項目中引入ts的詳細(xì)圖文教程

    最近項目需要將原vue項目結(jié)合ts的使用進(jìn)行改造,這個后面應(yīng)該是中大型項目的發(fā)展趨勢,下面這篇文章主要給大家介紹了關(guān)于vue3項目中引入ts的相關(guān)資料,需要的朋友可以參考下
    2022-09-09
  • 使用vue-router beforEach實現(xiàn)判斷用戶登錄跳轉(zhuǎn)路由篩選功能

    使用vue-router beforEach實現(xiàn)判斷用戶登錄跳轉(zhuǎn)路由篩選功能

    這篇文章主要介紹了vue使用vue-router beforEach實現(xiàn)判斷用戶登錄跳轉(zhuǎn)路由篩選,本篇文章默認(rèn)您已經(jīng)會使用 webpack 或者 vue-cli 來進(jìn)行環(huán)境的搭建,并且具有一定的vue基礎(chǔ)。需要的朋友可以參考下
    2018-06-06
  • vue-element-admin按鈕級權(quán)限管控的實現(xiàn)

    vue-element-admin按鈕級權(quán)限管控的實現(xiàn)

    開發(fā)離不開權(quán)限,不同的用戶登錄,根據(jù)不同的權(quán)限,可以訪問不同的管理目錄,本文主要介紹了vue-element-admin按鈕級權(quán)限管控的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2022-04-04
  • vue中監(jiān)聽input框獲取焦點及失去焦點的問題

    vue中監(jiān)聽input框獲取焦點及失去焦點的問題

    這篇文章主要介紹了vue中監(jiān)聽input框獲取焦點,失去焦點的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-07-07

最新評論

临城县| 察哈| 化州市| 修武县| 稻城县| 玛沁县| 敦化市| 清流县| 兴安县| 湾仔区| 闽清县| 枣庄市| 鄂州市| 团风县| 清流县| 安达市| 松江区| 海兴县| 旅游| 宜君县| 仁化县| 马鞍山市| 牙克石市| 常德市| 青岛市| 安康市| 西乡县| 岳西县| 聂拉木县| 汉源县| 松江区| 武功县| 宿迁市| 拉萨市| 桓台县| 竹北市| 获嘉县| 洛川县| 公主岭市| 盐边县| 镇沅|