Vue 實現(xiàn)對quill-editor組件中的工具欄添加title
前言:quill-editor組件中的工具欄都是英文,而且最難受的時沒有title提示,要怎樣給他添加title,并且是中文的title提示呢?
一、創(chuàng)建一個quill-title.js文件
①、在其中插入以下代碼
const titleConfig = {
'ql-bold':'加粗',
'ql-color':'顏色',
'ql-font':'字體',
'ql-code':'插入代碼',
'ql-italic':'斜體',
'ql-link':'添加鏈接',
'ql-background':'背景顏色',
'ql-size':'字體大小',
'ql-strike':'刪除線',
'ql-script':'上標(biāo)/下標(biāo)',
'ql-underline':'下劃線',
'ql-blockquote':'引用',
'ql-header':'標(biāo)題',
'ql-indent':'縮進(jìn)',
'ql-list':'列表',
'ql-align':'文本對齊',
'ql-direction':'文本方向',
'ql-code-block':'代碼塊',
'ql-formula':'公式',
'ql-image':'圖片',
'ql-video':'視頻',
'ql-clean':'清除字體樣式'
};
export function addQuillTitle(){
const oToolBar = document.querySelector('.ql-toolbar'),
aButton = oToolBar.querySelectorAll('button'),
aSelect = oToolBar.querySelectorAll('select');
aButton.forEach(function(item){
if(item.className === 'ql-script'){
item.value === 'sub' ? item.title = '下標(biāo)': item.title = '上標(biāo)';
}else if(item.className === 'ql-indent'){
item.value === '+1' ? item.title ='向右縮進(jìn)': item.title ='向左縮進(jìn)';
}else{
item.title = titleConfig[item.classList[0]];
}
});
aSelect.forEach(function(item){
item.parentNode.title = titleConfig[item.classList[0]];
});
}
②、在頁面中應(yīng)用
<template>
<quill-editor v-model="content" >
</quill-editor>
</template>
<script>
import { quillEditor } from 'vue-quill-editor'
import { addQuillTitle } from './quill-title.js'
export default {
components: {
quillEditor
},
mounted(){
addQuillTitle();
},
data() {
return {
content: '<h2>freddy</h2>',
}
}
}
</script>
③、運(yùn)行結(jié)果

像這樣鼠標(biāo)移入的時候就會顯示title了。
補(bǔ)充知識:自定義設(shè)置vue-quill-editor toolbar的title屬性
直接看代碼吧~
const titleConfig = {
'ql-bold':'加粗',
'ql-color':'字體顏色',
'ql-font':'字體',
'ql-code':'插入代碼',
'ql-italic':'斜體',
'ql-link':'添加鏈接',
'ql-background':'背景顏色',
'ql-size':'字體大小',
'ql-strike':'刪除線',
'ql-script':'上標(biāo)/下標(biāo)',
'ql-underline':'下劃線',
'ql-blockquote':'引用',
'ql-header':'標(biāo)題',
'ql-indent':'縮進(jìn)',
'ql-list':'列表',
'ql-align':'文本對齊',
'ql-direction':'文本方向',
'ql-code-block':'代碼塊',
'ql-formula':'公式',
'ql-image':'圖片',
'ql-video':'視頻',
'ql-clean':'清除字體樣式'
};
export function addQuillTitle(){
const oToolBar = document.querySelector('.ql-toolbar'),
aButton = oToolBar.querySelectorAll('button'),
aSelect = oToolBar.querySelectorAll('select'),
aSpan= oToolBar.querySelectorAll('span');
aButton.forEach((item)=>{
if(item.className === 'ql-script'){
item.value === 'sub' ? item.title = '下標(biāo)': item.title = '上標(biāo)';
}else if(item.className === 'ql-indent'){
item.value === '+1' ? item.title ='向右縮進(jìn)': item.title ='向左縮進(jìn)';
}else if(item.className === 'ql-list'){
item.value==='ordered' ? item.title='有序列表' : item.title='無序列表'
}else if(item.className === 'ql-header'){
item.value === '1' ? item.title = '標(biāo)題H1': item.title = '標(biāo)題H2';
}else{
item.title = titleConfig[item.classList[0]];
}
});
aSelect.forEach((item)=>{
if(item.className!='ql-color'&&item.className!='ql-background'){
item.parentNode.title = titleConfig[item.classList[0]];
}
});
aSpan.forEach((item)=>{
if(item.classList[0]==='ql-color'){
item.title = titleConfig[item.classList[0]];
}else if(item.classList[0]==='ql-background'){
item.title = titleConfig[item.classList[0]];
}
});
}
//how to use
//import { addQuillTitle } from './set-quill-title.js'
//addQuillTitle(); --use in mouted
//自定義 set title
以上這篇Vue 實現(xiàn)對quill-editor組件中的工具欄添加title就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決element-ui中下拉菜單子選項click事件不觸發(fā)的問題
今天小編就為大家分享一篇解決element-ui中下拉菜單子選項click事件不觸發(fā)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
詳解Vue改變數(shù)組中對象的屬性不重新渲染View的解決方案
這篇文章主要介紹了詳解Vue改變數(shù)組中對象的屬性不重新渲染View的解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
Vue3中實現(xiàn)代碼高亮的兩種方法(prismjs和highlight.js)
最近忙著開發(fā)自己的博客系統(tǒng),在做界面展示的時候,需要讓代碼高亮,于是經(jīng)過在網(wǎng)上查閱,發(fā)現(xiàn)有兩款比較好用的插件實現(xiàn)代碼高亮,分別是prismjs和highlight.js,下面我分別介紹下,方便給需要的同學(xué)參考2025-04-04
Vue組件間通信方法總結(jié)(父子組件、兄弟組件及祖先后代組件間)
這篇文章主要給大家介紹了關(guān)于Vue組件間通信的相關(guān)資料,其中包括父子組件、兄弟組件及祖先后代組件間的通信,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
Element InfiniteScroll無限滾動的具體使用方法
這篇文章主要介紹了Element InfiniteScroll無限滾動的具體使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
vue router使用query和params傳參的使用和區(qū)別
本篇文章主要介紹了vue router使用query和params傳參的使用和區(qū)別,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11

