vue 自定指令生成uuid滾動(dòng)監(jiān)聽達(dá)到tab表格吸頂效果的代碼
utils/index,.js
/** * 生成UUID * @param withSeparator 是否有分割符 * @returns {string} */ export function generateUUID(withSeparator = true) { let d = new Date().getTime() if (window.performance && typeof window.performance.now === 'function') { d += performance.now() } const tpl = withSeparator ? 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' : 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx' return tpl.replace(/[xy]/g, function(c) { const r = (d + Math.random() * 16) % 16 | 0 d = Math.floor(d / 16) return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) }) }
創(chuàng)建一個(gè)generate-uuid/index.js自定義指令文件
import { generateUUID } from '@/utils' const generateUuid = { inserted(el, binding) { const { value } = binding if (!value) { const hasUUID = generateUUID(value) el.setAttribute('data-uuid', hasUUID) if (!hasUUID) { el.parentNode && el.parentNode.removeChild(el) } } } } generateUuid.install = function(Vue) { Vue.directive('generate-uuid', generateUuid) } export default generateUuid
main.js引入
import GenerateUUID from '@/directive/generate-uuid' Vue.use(GenerateUUID)
頁(yè)面使用
<el-table v-generate-uuid="false" >
使用uuid元素方法
const topRow = this.$refs.multipleTable const hash = topRow.$el.dataset.uuid const tableHeader = document.querySelector(`.el-table[data-uuid="${hash}"] .el-table__header-wrapper`) if (tableHeader) { tableHeader.style.width = topRow.$el.getBoundingClientRect().width + 'px' }
總結(jié)
到此這篇關(guān)于vue 自定指令生成uuid滾動(dòng)監(jiān)聽達(dá)到tab表格吸頂效果的代碼的文章就介紹到這了,更多相關(guān)vue滾動(dòng)監(jiān)聽tab表格吸頂內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue實(shí)現(xiàn)導(dǎo)航欄點(diǎn)擊當(dāng)前標(biāo)簽變色功能
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)導(dǎo)航欄點(diǎn)擊當(dāng)前標(biāo)簽變色功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05Vue實(shí)現(xiàn)導(dǎo)出excel表格功能
這篇文章主要介紹了Vue實(shí)現(xiàn)導(dǎo)出excel表格的功能,在文章末尾給大家提到了vue中excel表格的導(dǎo)入和導(dǎo)出代碼,需要的朋友可以參考下2018-03-03Vue實(shí)現(xiàn)購(gòu)物車計(jì)算總價(jià)功能
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)購(gòu)物車計(jì)算總價(jià)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04解決Vue中使用Echarts出現(xiàn)There?is?a?chart?instance?already?ini
使用echarts的時(shí)候,多次加載會(huì)出現(xiàn)There?is?a?chart?instance?already?initialized?on?the?dom.這個(gè)黃色警告,此警告信息不影響echarts正常加載,但是有bug得解決,本文就帶大家解決這個(gè)問題,感興趣的同學(xué)可以參考閱讀2023-06-06vue中datepicker的使用教程實(shí)例代碼詳解
這篇文章主要介紹了vue-datepicker的使用,本文通過實(shí)例代碼大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07使用Vite+Vue3+Vant全家桶快速構(gòu)建項(xiàng)目步驟詳解
這篇文章主要為大家介紹了使用Vite+Vue3+Vant全家桶快速構(gòu)建項(xiàng)目步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06詳解如何使用Vue實(shí)現(xiàn)圖像識(shí)別和人臉對(duì)比
隨著人工智能的發(fā)展,圖像識(shí)別和人臉識(shí)別技術(shù)已經(jīng)被廣泛應(yīng)用于各種應(yīng)用程序中,Vue為我們提供了許多實(shí)用工具和庫(kù),可以幫助我們?cè)趹?yīng)用程序中進(jìn)行圖像識(shí)別和人臉識(shí)別,在本文中,我們將介紹如何使用Vue進(jìn)行圖像識(shí)別和人臉對(duì)比,需要的朋友可以參考下2023-06-06