vue element-ui el-tooltip組件失效問題及解決
vue element-ui el-tooltip組件失效
起因
因?yàn)楣卷?xiàng)目年代久遠(yuǎn)以及谷歌chrome 80 后的samesite問題,所以在開發(fā)階段使用Firefox來查看效果
項(xiàng)目上到測試環(huán)境之后,我這邊使用Firefox查看效果是沒有問題的,tooltip組件正式顯示
但是當(dāng)測試使用Chrome的時(shí)候,tooltip組件沒有顯示,審查元素也發(fā)現(xiàn)沒有相應(yīng)的tooltip的html元素出現(xiàn),正常來講應(yīng)該是要出現(xiàn)類似以下的html元素的
最后經(jīng)過大量百度(bushi) 以及查閱github的issue之后得出:
當(dāng)el-tooltip組件內(nèi)直接放置文本或者單一元素的時(shí)候,在Chrome會(huì)有tooltip不出現(xiàn)的問題,在Firefox卻不會(huì)
<template> <!-- 直接放置文本 --> <el-tooltip class="item" effect="dark" content="tooptip" placement="top-start"> 直接放置文本 </el-tooltip> <!-- 單一元素 --> <el-tooltip class="item" effect="dark" content="tooptip" placement="top-start"> <textarea v-model="value" @change="updata"></textarea> </el-tooltip> </template>
嘗試解決
但是如果你用一個(gè)盒子去包裹的話,它又可以了?。。?/p>
<template> <el-tooltip class="item" effect="dark" content="tooptip" placement="top-start"> <p>用一個(gè)p標(biāo)簽包裹文本</p> </el-tooltip> <el-tooltip class="item" effect="dark" content="tooptip" placement="top-start"> <div> <textarea v-model="value" @change="updata"></textarea> </div> </el-tooltip> </template>
心得
在使用el-tooptip組件時(shí)應(yīng)該始終用一個(gè)盒子去包裹住里面的元素
vue element-ui 使用el-tooltip內(nèi)部嵌套其他element-ui組件時(shí)報(bào)錯(cuò)
現(xiàn)象:
[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'style')"
found in
---> <ElSwitch> at packages/switch/src/component.vue
<ElTooltip>
<ElDialog> at packages/dialog/src/component.vue
<OffSeasonStorage>
<CustomizationDetails> at src/views/equipment/components/Customization.vue
<AppMain> at src/layout/components/AppMain.vue
<Layout> at src/layout/index.vue
<App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js?2b0e:619
vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading 'style')
at VueComponent.setBackgroundColor (element-ui.common.js?5c96:7289:1)
at VueComponent.mounted (element-ui.common.js?5c96:7314:1)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1863:1)
at callHook (vue.runtime.esm.js?2b0e:4235:1)
at Object.insert (vue.runtime.esm.js?2b0e:3158:1)
at invokeInsertHook (vue.runtime.esm.js?2b0e:6390:1)
at VueComponent.patch [as __patch__] (vue.runtime.esm.js?2b0e:6609:1)
at Vue._update (vue.runtime.esm.js?2b0e:3963:1)
at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4081:1)
at Watcher.get (vue.runtime.esm.js?2b0e:4495:1)
logError @ vue.runtime.esm.js?2b0e:1897
代碼:
<el-dialog :visible.sync="dialogVisible" :close-on-click-modal="false" :destroy-on-close="true" :before-close="closeFunc" :lock-scroll="false" :append-to-body="true" top="" > <el-tooltip v-model="item.tooltip" effect="dark" :manual="true" placement="left"> <div slot="content"> <div> <div>tips</div> </div> </div> <div> <el-switch v-model="item.switch" class="switch" :width="60" active-color="#AE0F0A" inactive-color="#DDDDDD" @change="switchChangeFuc(item)" > </el-switch> </div> </el-tooltip> </el-dialog>
解決方案
根據(jù)dialog的展示與否重新渲染el-switch
<el-switch v-if="dialogVisible" v-model="item.switch" class="switch" :width="60" active-color="#AE0F0A" inactive-color="#DDDDDD" @change="switchChangeFuc(item)" > </el-switch>
結(jié)果:問題解決
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue3+el-table實(shí)現(xiàn)行列轉(zhuǎn)換
在處理文本數(shù)據(jù)的時(shí)候,我們經(jīng)常會(huì)需要把文本數(shù)據(jù)的行與列進(jìn)行轉(zhuǎn)換操作,這樣更方便查看,本文就詳細(xì)的介紹了vue3+el-table實(shí)現(xiàn)行列轉(zhuǎn)換,感興趣的可以了解一下2021-06-06vue3中vue.config.js配置Element-plus組件和Icon圖標(biāo)實(shí)現(xiàn)按需自動(dòng)引入實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于vue3中vue.config.js配置Element-plus組件和Icon圖標(biāo)實(shí)現(xiàn)按需自動(dòng)引入的相關(guān)資料,在Vue 3中可以通過配置vue.config.js文件來進(jìn)行按需自動(dòng)引入,需要的朋友可以參考下2024-02-02Vue 樣式切換及三元判斷樣式關(guān)聯(lián)操作
這篇文章主要介紹了Vue 樣式切換及三元判斷樣式關(guān)聯(lián)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08vue項(xiàng)目中圖片選擇路徑位置static或assets的區(qū)別及說明
這篇文章主要介紹了vue項(xiàng)目中圖片選擇路徑位置static或assets的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09vue-resource攔截器設(shè)置頭信息的實(shí)例
下面小編就為大家?guī)硪黄獀ue-resource攔截器設(shè)置頭信息的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10vue項(xiàng)目element UI input框掃碼槍掃描過快出現(xiàn)數(shù)據(jù)丟失問題及解決方案
這篇文章主要介紹了vue項(xiàng)目element UI input框掃碼槍掃描過快出現(xiàn)數(shù)據(jù)丟失問題,輸入框要掉兩個(gè)接口,根據(jù)第一個(gè)驗(yàn)證接口返回的code,彈不同的框,點(diǎn)擊彈框確認(rèn)再掉第二個(gè)接口,需要的朋友可以參考下2022-12-12