您现在的位置是:主页 > news > 正规做网站/seo推广论坛
正规做网站/seo推广论坛
admin2025/6/12 21:30:37【news】
简介正规做网站,seo推广论坛,网站建设法律,娱乐网站建设ppt模板首先使用 npm i vue-quill-editor -save 安装vue-quill-editor第二、我们新建一个.vue文件存放当前的富文本编辑器,这里我会使用全局组件使用引入,当然,你也可以使用局部组件,使用方式相同,废话不多说,直接…
正规做网站,seo推广论坛,网站建设法律,娱乐网站建设ppt模板首先使用 npm i vue-quill-editor -save 安装vue-quill-editor第二、我们新建一个.vue文件存放当前的富文本编辑器,这里我会使用全局组件使用引入,当然,你也可以使用局部组件,使用方式相同,废话不多说,直接…
首先使用 npm i vue-quill-editor -save 安装vue-quill-editor
第二、我们新建一个.vue文件存放当前的富文本编辑器,这里我会使用全局组件使用引入,当然,你也可以使用局部组件,使用方式相同,废话不多说,直接贴代码,这个使用vant图片上传,因为vue-quill-editor在ios是点不开的
<!-- 模板 -->
<template><div class="editor"><quill-editorv-model="content"ref="myQuillEditor":options="options":disabled="redact"@change="onEditorChange($event)"></quill-editor><van-uploader v-show="false" :afterRead="afterRead" :beforeRead="beforeRead"><van-button icon="photo" type="primary">上传图片</van-button></van-uploader></div><!-- <div class="ql-editor" v-html="content"></div> -->
</template><script>
import "quill/dist/quill.core.css"; //引入样式
import "quill/dist/quill.snow.css";//引入样式
import "quill/dist/quill.bubble.css";//引入样式import { quillEditor } from "vue-quill-editor";//引入组件
export default {name: "quillEditors",props: {//是否可以编辑redact: {type: Boolean,default: false},//头部是否可显示title: {type: Boolean,default: false}},data() {return {content: ``,options: {placeholder: "请输入模板...",modules: {toolbar: {container: [["bold", "italic", "underline", "strike"], //切换按钮 //bold 加粗 italic 斜 underline 下划线 strike删除线["blockquote", "code-block"], //blockquote 引用 code-block 代码块["link", "image"], //图片 link 链接 image图片[{ header: 1 }, { header: 2 }], // 标题,键值对的形式;1、2表示字体大小[{ list: "ordered" }, { list: "bullet" }], //排序 ordered 有序 bullet 无序// [{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题[{ script: "sub" }, { script: "super" }], // sub上标 / super下标[{ indent: "-1" }, { indent: "+1" }], // 减少缩进/缩进[{ direction: "rtl" }], // 文本方向[{ color: [] }, { background: [] }], // color 字体颜色 background 背景颜色 从主题默认下拉[{ align: [] }], //文本对齐方式[{ font: [] }], //字体格式[{ size: [] }] // 自定义下拉],handlers: {image: value => {if (value) {//禁止软键盘弹出document.activeElement.blur();// 触发input框选择图片文件document.querySelector(".van-uploader input").click();} else {this.quill.format("image", false);}}}}}}};},computed: {},watch: {//title变化时触发title(bool) {if (bool) {document.querySelector(".quill-editor .ql-toolbar").style.display ="none";}}},methods: {//图片上传成功afterRead(file) {console.log("后", file);},//图片上传前async beforeRead(file) {console.log("前", file, file.size / 1024);if (file.size == 0) {return false}if (!/^image/(jpeg|png|jpg)$/.test(file.type)) {this.$toast("请上传 jpg,jpeg,png 格式图片");return false;}this.$toast.allowMultiple();let loading = this.$toast.loading({duration: 0,mask: false,forbidClick: true,message: "上传中..."});let fr = new FormData();fr.append("image", file);try {let quill = this.$refs.myQuillEditor.quill;let { msg, code, data } = await this.$post("img/V1/uploadImage", fr);if (code === 1) {console.log("上传成功", data[0]);// 获取光标所在位置let length = quill.getSelection().index;// 插入图片quill.insertEmbed(length, "image", data[0]);// 调整光标到最后quill.setSelection(length + 1);return true;} else {this.$toast(`${msg}`);}} catch (err) {console.log("错误", err);this.$toast("网络错误,请检查网络连接!");} finally {loading.clear();}},//内容改变触发onEditorChange() {this.$emit("ChangeText", this.content);}},mounted() {//初始化titlethis.title == true? (document.querySelector(".quill-editor .ql-toolbar").style.display ="none"): "";},components: { quillEditor }// components: { editor }
};
</script>
<style lang='scss' >
.editor {height: 80%;position: relative;display: flex;flex-direction: column;.quill-editor {height: 100%;}.ql-toolbar {z-index: inherit;// position: absolute;// top: 0;}.ql-container {flex: 1;s,i,em {font-style: italic;text-decoration: line-through;}}
}
</style>
在main.js引入组件
import QuillEditors from './components/QuillEditors' //富文本编辑器
Vue.component('quill-editors', QuillEditors)//全局组件
使用
<template><quill-editors @ChangeText="(text)=>{content=text}" :title="title" />
</template>
踩坑
- vue-quill-editor 空格并不会加 要手动处理
cent = cent.replace(/s/g, " ");
cent = cent.replace(/(img )/g, "img ");
2.不支持表格,弃坑吧(这也是不继续弄得原因)