vue 判斷元素內(nèi)容是否超過寬度的方式
我就廢話不多說了,大家還是直接看代碼吧~
let isOverflow = this.$refs.isOverflow;for (let i in isOverflow) { let cWidth = isOverflow[i].clientWidth; let sWidth = isOverflow[i].scrollWidth; if (sWidth > cWidth) { //超過 this.$set(this.isEllipsis, i, true); } else { this.$set(this.isEllipsis, i, false); }}
補充知識:Vue h5 里面如何動態(tài)設置返回時候meta 里面的title屬性
Vue h5 里面如何動態(tài)設置返回時候meta 里面的title屬性
百度了很多博客,有兩種方法,
方法1 :
通過設置router.js 里面,路由切換時候 修改 meta 屬性 但是感覺沒必要這樣
{ path: ’/teachers’, name: ’TDetail’, component: TDetail, meta: { title:'教師詳情', content: ’disable’ } }, { path: ’/article’, name: ’Article’, component: Article, meta: { title: '文章詳情', content: ’disable-no’ } }, //main.js里面的代碼 router.beforeEach((to, from, next) => { /* 路由發(fā)生變化修改頁面meta */ if(to.meta.content){ let head = document.getElementsByTagName(’head’); let meta = document.createElement(’meta’); meta.content = to.meta.content; head[0].appendChild(meta) } /* 路由發(fā)生變化修改頁面title */ if (to.meta.title) { document.title = to.meta.title; } next()});
方法2 :
可以直接通過
document.title = ’想要設置的title’;
但是需要注意的是,這種寫法需要注意Vue 里面的生命周期,需要在beforeRouteEnter 里面設置,下面是代碼
beforeRouteEnter (to, from, next) { next(vm => { document.title = ’律師大數(shù)據(jù)’ }) },
但是開發(fā)里面遇到了坑,有時候這種寫法根本不起效果,然后嘗試在 beforeCreate里面也設置了下,最終總結(jié)出來的規(guī)律是,如果 只在 beforeRouteEnter 修改 document.title = ’想要設置的title’;不起效果的話,那就同時也把 beforeCreate寫進來,這樣肯定是能改變 頁面的 meta 屬性的,下面是代碼
beforeCreate () { document.title = ’111律師大數(shù)據(jù)’ }, beforeRouteEnter (to, from, next) { next(vm => { document.title = ’律師大數(shù)據(jù)’ }) },
但是 ,經(jīng)過打印,實際起效果的是,beforeRouteEnter里面設置的 document.title = ’律師大數(shù)據(jù)’
以上這篇vue 判斷元素內(nèi)容是否超過寬度的方式就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 利用CSS3新特性創(chuàng)建透明邊框三角2. html清除浮動的6種方法示例3. CSS代碼檢查工具stylelint的使用方法詳解4. Vue3使用JSX的方法實例(筆記自用)5. vue實現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細教程6. CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)7. 詳解CSS偽元素的妙用單標簽之美8. 使用css實現(xiàn)全兼容tooltip提示框9. JavaScript數(shù)據(jù)類型對函數(shù)式編程的影響示例解析10. 不要在HTML中濫用div
