Vue项目中---文本框中加入simditor编辑器
生活随笔
收集整理的這篇文章主要介紹了
Vue项目中---文本框中加入simditor编辑器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
官網(wǎng)地址:
https://simditor.tower.im效果圖
使用步驟
1.安裝環(huán)境(建議按此版本安裝,其他版本可能不兼容)
//安裝simditor npm install simditor@2.3.6 //卸載simditor npm uninstall simditor//安裝jquery npm uninstall jquery //卸載jquery npm install jquery@3.4.12.代碼
封裝的組件代碼
<template><div class="simditor"><textarea :id="id"></textarea></div> </template> <script> import $ from "jquery"; import Simditor from "simditor"; import "simditor/styles/simditor.css"; export default {name: "simditor",data() {return {editor: "",};},props: {id: "", //這里傳入動(dòng)態(tài)id,一個(gè)頁面能使用多個(gè)編輯器options: {//配置參數(shù)type: Object,default() {return {};},},},mounted() {let vm = this;this.editor = new Simditor(Object.assign({},{textarea: $(`#${vm.id}`),},this.options));this.editor.on("valuechanged", (e, src) => {this.valueChange(e, src);});},methods: {valueChange(e, val) {this.$emit("change", this.editor.getValue());},}, }; </script><!-- Add "scoped" attribute to limit CSS to this component only --> <style> </style>組件使用
<template><div class="index"><simditor :options="options" id="1" @change="change" style="width: 400px"></simditor></div> </template> <script> import Simditor from "../components/Simditor"; export default {name: "index",data() {return {content: "",//工具欄配置項(xiàng)options: {placeHolder: "this is placeHolder",toolbarFloat: false,toolbar: ["bold","italic","title","link","image","ol","ul","indent","outdent","alignment",// "underline",// "strikethrough",// "fontScale","color",// "|",// "blockquote",// "code",// "table",// "|",// "hr",// "|",],pasteImage: true, //占位符(圖片)upload: {url: `http://...`, //文件上傳的接口地址params: null, //鍵值對,指定文件上傳接口的額外參數(shù),上傳的時(shí)候隨文件一起提交fileKey: "file", //服務(wù)器端獲取文件數(shù)據(jù)的參數(shù)名connectionCount: 3, //同時(shí)上傳多少張圖片leaveConfirm: "正在上傳文件",},},};},components: {Simditor,},methods: {change(val) {console.log(val); //以html格式獲取simditor的正文內(nèi)容},}, }; </script><style > .simditor .simditor-body {min-height: 150px !important; } .simditor {border: 1px solid #eeeeee !important; } </style>總結(jié)
以上是生活随笔為你收集整理的Vue项目中---文本框中加入simditor编辑器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【JS继承】JS继承之寄生式继承
- 下一篇: 书签整理