vue3中使用editor.js的詳細(xì)步驟記錄
第一步安裝依賴
npm i @editorjs/editorjs --save
第二步創(chuàng)建editor.vue插件
<template> <div> <div id="editorjs" :style="'width:' + props.width + 'px;height:' + props.height + 'px;'"></div> </div> </template> <script setup> // 標(biāo)題(Header):用于設(shè)置文本的標(biāo)題級(jí)別,支持多級(jí)標(biāo)題。 // 段落(Paragraph):用于添加普通文本段落。 // 引用(Quote):用于添加引用文本塊。 // 列表(List):支持有序列表和無(wú)序列表。 // 圖像(Image):可以插入圖片,并指定圖片的來(lái)源、標(biāo)題和描述等屬性。 // 插入鏈接(Link):可以插入超鏈接,指定鏈接的URL、標(biāo)題和打開(kāi)方式等。 // 視頻(Embed):可以插入媒體內(nèi)容的外部嵌入代碼或鏈接。 // 表格(Table):可以創(chuàng)建簡(jiǎn)單的表格,指定表格行數(shù)和列數(shù)。 // 代碼(Code):用于插入代碼塊,支持多種編程語(yǔ)言的語(yǔ)法高亮。 // 內(nèi)容警告(Warning):用于突出顯示重要提示或警告。 // 勾選框(Checklist):用于創(chuàng)建待辦事項(xiàng)列表,可以勾選完成狀態(tài)。 // 分割線(Delimiter):用于在內(nèi)容中插入水平分割線。 import EditorJS from '@editorjs/editorjs'; import Header from '@editorjs/header'; import List from '@editorjs/list'; import Paragraph from '@editorjs/paragraph'; import Quote from '@editorjs/quote'; import Image from '@editorjs/image'; import Embed from '@editorjs/embed'; import Table from '@editorjs/table'; import Code from '@editorjs/code'; import Delimiter from '@editorjs/delimiter'; import zh from './i18n.json' import { useRouter, useRoute } from 'vue-router' const router = useRouter() const route = useRoute() const store = useStore() const { ctx, proxy } = getCurrentInstance() const emit = defineEmits(['update:modelValue']) const props = defineProps({ modelValue: { type: String, default: "", }, width: { type: Number, default: 500, }, height: { type: Number, default: 500, }, }) const editor = ref(null) const saveEditor = () => { editor.value.save().then((outputData) => { console.log(outputData) }).catch((error) => { console.log(error) }); } const { data } = toRefs(reactive({ //定義數(shù)組和對(duì)象 data: '' })) onMounted(() => { editor.value = new EditorJS({ holder: 'editorjs',//應(yīng)該包含編輯器的元素Id // autofocus: true,//自動(dòng)獲取焦點(diǎn) placeholder: '請(qǐng)輸入內(nèi)容', i18n: { messages: zh }, logLevel: 'VERBOSE',//日志級(jí)別 VERBOSE顯示所有消息(默認(rèn)) INFO顯示信息和調(diào)試消息 WARN只顯示警告消息 ERROR只顯示錯(cuò)誤信息 readOnly: false,//只讀模式 tools: {//工具列表 header: { class: Header, inlineToolbar: ['link'] }, list: { class: List, inlineToolbar: true }, paragraph: { class: Paragraph, inlineToolbar: true }, quote: { class: Quote, inlineToolbar: true }, // image: SimpleImage, image: { class: Image, inlineToolbar: true }, embed: { class: Embed, inlineToolbar: true }, table: { class: Table, inlineToolbar: true }, code: { class: Code, inlineToolbar: true }, delimiter: { class: Delimiter, inlineToolbar: true }, }, onReady: () => { console.log('Editor.js is ready to work!') }, }) console.log(editor.value); }) // watch(propData,(newVal,oldVal)=>{}) defineExpose({ saveEditor }) </script> <style scoped></style>
創(chuàng)建i18n翻譯文件 i18n.json
{ "ui": { "blockTunes": { "toggler": { "Click to tune": "點(diǎn)擊調(diào)整", "or drag to move": "或者拖動(dòng)移動(dòng)" } }, "inlineToolbar": { "converter": { "Convert to": "轉(zhuǎn)換為" } }, "toolbar": { "toolbox": { "Add": "添加" } } }, "toolNames": { "Text": "文本", "Heading": "標(biāo)題", "List": "列表", "Warning": "警告", "Checklist": "清單", "Quote": "引用", "Code": "代碼", "Delimiter": "分隔符", "Raw HTML": "原始HTML", "Table": "表格", "Link": "鏈接", "Marker": "標(biāo)記", "Bold": "加粗", "Italic": "斜體", "Image": "圖片" }, "tools": { "warning": { "Title": "標(biāo)題", "Message": "消息" }, "link": { "Add a link": "添加鏈接" }, "stub": { "The block can not be displayed correctly.": "該塊不能正確顯示" } }, "blockTunes": { "delete": { "Delete": "刪除" }, "moveUp": { "Move up": "向上移動(dòng)" }, "moveDown": { "Move down": "向下移動(dòng)" } } }
在頁(yè)面引入組件
<template> <div class="editorBox"> <editorJs ref="editorRef" :width="700" :height="1000" v-model="data"></editorJs> <el-button @click="save">保存</el-button> </div> </template> <script setup> import editorJs from '@/components/Editor/editorJs' import { useRouter, useRoute } from 'vue-router' const router = useRouter() const route = useRoute() const store = useStore() const { ctx, proxy } = getCurrentInstance() const emit = defineEmits(['update:modelValue']) const props = defineProps({ propData: { type: String, default: '', }, }) const { data } = toRefs(reactive({ //定義數(shù)組和對(duì)象 data: '' })) const editorRef = ref(null)//定義普通類型 function save() { editorRef.value.saveEditor() } // onMounted(() => {}) // watch(propData,(newVal,oldVal)=>{}) </script> <style scoped> .editorBox { padding: 40px; width: 700px; background-color: #fff; margin: 50px auto auto; box-shadow: 0 1px 4px rgba(0, 0, 0, .04), 0 4px 10px rgba(0, 0, 0, .08); } </style>
這只是一個(gè)簡(jiǎn)單的示例,具體配置請(qǐng)去官網(wǎng)Editor.js (editorjs.io)
Editor.js
在其核心設(shè)計(jì)中不直接包含一個(gè)傳統(tǒng)的“頂部工具欄”。它的設(shè)計(jì)理念是簡(jiǎn)潔、無(wú)干擾的用戶體驗(yàn),焦點(diǎn)是在“塊”內(nèi)容上,而非傳統(tǒng)的富文本編輯器的樣式。因此,Editor.js
的默認(rèn)設(shè)置下,不會(huì)顯示類似 Word 或其他傳統(tǒng)編輯器的頂部工具欄。
說(shuō)一下我的心得:
官方文檔對(duì)中文及其不友好,不建議使用這個(gè)編輯器,除非你有大量時(shí)間來(lái)開(kāi)發(fā)研究
Editor.js 是一個(gè)用于構(gòu)建具有完全可定制化塊結(jié)構(gòu)的現(xiàn)代編輯器的開(kāi)源庫(kù)。它提供了一個(gè)簡(jiǎn)潔、可擴(kuò)展和易于使用的接口,使開(kāi)發(fā)人員能夠創(chuàng)建擁有豐富內(nèi)容和互動(dòng)性的編輯器。
以下是一些 Editor.js 的特點(diǎn)和優(yōu)勢(shì):
塊結(jié)構(gòu):Editor.js 采用了塊結(jié)構(gòu)的概念,將內(nèi)容分解為可獨(dú)立操作和樣式化的不同塊,如段落、標(biāo)題、圖像、列表等。這種結(jié)構(gòu)使得對(duì)內(nèi)容的編輯和擴(kuò)展變得更加直觀和靈活。
嵌套塊:不僅可以創(chuàng)建單一塊的內(nèi)容,還可以在塊內(nèi)部創(chuàng)建嵌套結(jié)構(gòu),構(gòu)建復(fù)雜的內(nèi)容組合。例如,你可以在段落塊中嵌套標(biāo)題、列表或引用塊等。
簡(jiǎn)潔的用戶界面:Editor.js 的用戶界面被設(shè)計(jì)成簡(jiǎn)潔、直觀且易于使用。用戶可以通過(guò)簡(jiǎn)單的操作來(lái)創(chuàng)建、編輯和刪除塊,不需要關(guān)注復(fù)雜的標(biāo)記語(yǔ)法或樣式細(xì)節(jié)。
開(kāi)放的插件系統(tǒng):Editor.js 提供了一個(gè)強(qiáng)大的插件系統(tǒng),允許開(kāi)發(fā)人員創(chuàng)建自定義塊類型和擴(kuò)展編輯器功能。你可以根據(jù)需要編寫自己的塊插件,并將其集成到編輯器中,以滿足特定的編輯需求。
豐富的內(nèi)容保存:Editor.js 使用 JSON 格式保存編輯器的內(nèi)容。這種格式簡(jiǎn)單易懂,便于存儲(chǔ)和傳輸,同時(shí)保留了塊結(jié)構(gòu)和樣式的信息。你可以將編輯器的內(nèi)容保存到數(shù)據(jù)庫(kù)中,然后在需要時(shí)重新加載。
可擴(kuò)展的主題和樣式:Editor.js 的外觀和樣式可以根據(jù)你的品牌和設(shè)計(jì)需求進(jìn)行定制。你可以創(chuàng)建自己的主題或使用現(xiàn)有的主題來(lái)改變編輯器的外觀。
多語(yǔ)言支持:Editor.js 支持多種語(yǔ)言,可以輕松地切換編輯器的顯示語(yǔ)言或自定義特定術(shù)語(yǔ)的翻譯。
總而言之,Editor.js 是一個(gè)功能強(qiáng)大、靈活且易于使用的編輯器庫(kù),適用于構(gòu)建各種應(yīng)用程序中的富文本編輯功能,如內(nèi)容管理系統(tǒng)、博客平臺(tái)、電子商務(wù)平臺(tái)等。它提供了現(xiàn)代化的編輯體驗(yàn),同時(shí)讓開(kāi)發(fā)人員能夠自由定制編輯器以滿足個(gè)性化需求。
總結(jié)
到此這篇關(guān)于vue3中使用editor.js的文章就介紹到這了,更多相關(guān)vue3使用editor.js內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決Vue不能檢測(cè)數(shù)組或?qū)ο笞儎?dòng)的問(wèn)題
下面小編就為大家分享一篇解決Vue不能檢測(cè)數(shù)組或?qū)ο笞儎?dòng)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02Vue3新屬性之css中使用v-bind的方法(v-bind?in?css)
這篇文章主要介紹了Vue3新屬性css中使用v-bind(v-bind?in?css)的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01詳解如何在Vue2中實(shí)現(xiàn)useDraggable
這篇文章主要為大家詳細(xì)介紹了Vue2中實(shí)現(xiàn)useDraggable的相關(guān)知識(shí),文中的示例代碼簡(jiǎn)潔易懂,對(duì)我們深入了解vue有一定的幫助,需要的小伙伴可以參考下2023-12-12vue-cli2,vue-cli3,vite?生產(chǎn)環(huán)境去掉console.log
console.log一般都是在開(kāi)發(fā)環(huán)境下使用的,在生產(chǎn)環(huán)境下需要去除?,本文主要介紹了vue-cli2,vue-cli3,vite?生產(chǎn)環(huán)境去掉console.log,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05vue實(shí)現(xiàn)商品加減計(jì)算總價(jià)的實(shí)例代碼
這篇文章主要介紹了vue實(shí)現(xiàn)商品加減計(jì)算總價(jià)的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08利用Vue3實(shí)現(xiàn)拖拽定制化首頁(yè)功能
vue3正式版已經(jīng)發(fā)布大半年了,咱也得緊跟時(shí)代潮流,vue3帶來(lái)的很多改變,下面這篇文章主要給大家介紹了關(guān)于利用Vue3實(shí)現(xiàn)拖拽定制化首頁(yè)功能的相關(guān)資料,需要的朋友可以參考下2022-05-05Vue?Router路由hash模式與history模式詳細(xì)介紹
Vue?Router是Vue.js官方的路由管理器。它和Vue.js的核心深度集成,讓構(gòu)建單頁(yè)面應(yīng)用變得易如反掌。路由實(shí)際上就是可以理解為指向,就是我在頁(yè)面上點(diǎn)擊一個(gè)按鈕需要跳轉(zhuǎn)到對(duì)應(yīng)的頁(yè)面,這就是路由跳轉(zhuǎn)2022-08-08VUE + UEditor 單圖片跨域上傳功能的實(shí)現(xiàn)方法
這篇文章主要介紹了VUE + UEditor 單圖片跨域上傳功能的實(shí)現(xiàn)方法,需要的朋友參考下2018-02-02