当前位置: 首页 > news >正文

地产网站模板杭州网站推广优化

地产网站模板,杭州网站推广优化,企业官网网页设计,网络域名是什么前言 使用富文本编辑器,需要将图片上传到服务器,完成之后,还需要在修改页面完成修改富文本内容,使用的富文本插件是vue-quill-editor, 一 、安装 vue-quill-editor npm i vue-quill-editor npm install quill --save npm inst…

前言

使用富文本编辑器,需要将图片上传到服务器,完成之后,还需要在修改页面完成修改富文本内容,使用的富文本插件是vue-quill-editor,
在这里插入图片描述

一 、安装 vue-quill-editor

npm i vue-quill-editor
npm install quill --save
npm install quill-image-resize-module --save // 图片缩放组件引用
npm i quill-image-drop-module  -S // 图片拖动组件引用
npm install axios // 上传阿里云服务器用

二、引入

import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import { quillEditor, Quill } from 'vue-quill-editor';
import axios from 'axios';// 如果要图片拖拽功能,增加这两个插件
import { ImageDrop } from "quill-image-drop-module"; // 图片拖动组件引用
import ImageResize from "quill-image-resize-module"; // 图片缩放组件引用
Quill.register("modules/imageDrop", ImageDrop); // 注册
Quill.register("modules/imageResize", ImageResize); // 注册

三、配置 vue.config

const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack') // 引入webpack
module.exports = defineConfig({configureWebpack: {plugins: [new webpack.ProvidePlugin({'window.Quill': 'quill/dist/quill.js','Quill': 'quill/dist/quill.js'})]},
})

四 、上传图片到阿里云成功后的图片显示预览

在这里插入图片描述

五、富文本组件代码

<template><div class="editor"><quill-editor class="ql-editor" v-model="content" ref="myQuillEditor" :options="editorOption"@blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)"></quill-editor></div>
</template><script>
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import { quillEditor, Quill } from 'vue-quill-editor';
import axios from 'axios';// 如果要图片拖拽功能,增加这两个插件
import { ImageDrop } from "quill-image-drop-module"; // 图片拖动组件引用
import ImageResize from "quill-image-resize-module"; // 图片缩放组件引用
Quill.register("modules/imageDrop", ImageDrop); // 注册
Quill.register("modules/imageResize", ImageResize); // 注册export default {name: "customEditor",components: {quillEditor},props: {value: {type: String,default: ''}},watch: {value(newValue) {this.content = newValue; // 监听 props.value 的变化},content(newValue) {this.$emit('content-changed', newValue); // 向父组件发出事件}},data() {return {content: this.value,editorOption: {modules: {toolbar: [["bold", "italic", "underline", "strike"], //加粗,斜体,下划线,删除线["blockquote", "code-block"], //引用,代码块[{ header: 1 }, { header: 2 }], // 标题,键值对的形式;1、2表示字体大小[{ list: "ordered" }, { list: "bullet" }], //列表[{ script: "sub" }, { script: "super" }], // 上下标[{ indent: "-1" }, { indent: "+1" }], // 缩进[{ direction: "rtl" }], // 文本方向[{ size: ["small", false, "large", "huge"] }], // 字体大小[{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题[{ color: [] }, { background: [] }], // 字体颜色,字体背景颜色[{ font: [] }], //字体[{ align: [] }], //对齐方式["clean"], //清除字体样式["image",], //上传图片、上传视频 "video"]},imageDrop: true,imageResize: {displayStyles: {backgroundColor: 'black',border: 'none',color: 'white'},modules: ['Resize', 'DisplaySize', 'Toolbar']}},};},mounted() {// 获取工具栏实例并覆盖图片处理函数const toolbar = this.$refs.myQuillEditor.quill.getModule('toolbar');toolbar.addHandler('image', this.handleImageUpload);},methods: {// 处理图片上传事件handleImageUpload() {const input = document.createElement('input');input.setAttribute('type', 'file');input.setAttribute('accept', 'image/*');input.onchange = async () => {const file = input.files[0];if (file) {await this.uploadImage(file);}};input.click();},// 上传图片到阿里云服务器async uploadImage(file) {// console.log("file", file);try {// 获取阿里云上传凭证const res = await this.$axios("feiyong/ossNews")// console.log("res", JSON.parse(JSON.stringify(res)));const formData = new FormData();const fileName = res.data.dir + res.data.gsid + '/' + `${Date.now()}_${Math.random()}`;// 添加必要字段formData.append("key", fileName); // 最终存储的文件名formData.append("policy", res.data.policy);formData.append("OSSAccessKeyId", res.data.accessid);formData.append('success_action_status', "200");formData.append("signature", res.data.signature);formData.append("callback", res.data.callback);formData.append("file", file); // 图片文件      // 发送上传请求const uploadRes = await axios.post(res.data.host, formData);// 获取图片URLconst imageUrl = `${res.data.host}/${uploadRes.data.data.filename}${res.data.style2}`;// const imageUrl = `${res.data.host}/${uploadRes.data.data.filename}${res.data.style1}`;// 插入图片到编辑器this.insertImageToEditor(imageUrl);} catch (error) {console.error('上传失败', error.response ? error.response.data : error.message);}},// 插入图片到编辑器insertImageToEditor(url) {const range = this.$refs.myQuillEditor.quill.getSelection();this.$refs.myQuillEditor.quill.insertEmbed(range.index, 'image', url);this.$refs.myQuillEditor.quill.setSelection(range.index + 1);},async onEditorChange({ html}) {// console.log(quill, "quill");// console.log(text, "text");// console.log(html, "html");this.content = html;this.$emit('content-changed', html); // 发出事件},onEditorBlur(e) {console.log(e, '失去焦点事件');},onEditorFocus(e) {console.log(e, '获得焦点事件');},},};
</script><style lang="less">
.ql-snow .ql-tooltip[data-mode="link"]::before {content: "请输入链接地址:";
}.ql-snow .ql-tooltip.ql-editing a.ql-action::after {border-right: 0px;content: "保存";padding-right: 0px;
}.ql-snow .ql-tooltip[data-mode="video"]::before {content: "请输入视频地址:";
}.ql-snow .ql-picker.ql-size .ql-picker-label::before,
.ql-snow .ql-picker.ql-size .ql-picker-item::before {content: "14px";
}.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="small"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="small"]::before {content: "10px";
}.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="large"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="large"]::before {content: "18px";
}.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="huge"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="huge"]::before {content: "32px";
}.ql-snow .ql-picker.ql-header .ql-picker-label::before,
.ql-snow .ql-picker.ql-header .ql-picker-item::before {content: "文本";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {content: "标题1";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {content: "标题2";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before {content: "标题3";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="4"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="4"]::before {content: "标题4";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="5"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="5"]::before {content: "标题5";
}.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="6"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="6"]::before {content: "标题6";
}.ql-snow .ql-picker.ql-font .ql-picker-label::before,
.ql-snow .ql-picker.ql-font .ql-picker-item::before {content: "标准字体";
}.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="serif"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="serif"]::before {content: "衬线字体";
}.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="monospace"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="monospace"]::before {content: "等宽字体";
}.edit_container {width: 100%;
}:deep(.ql-editor) {min-height: 400px;
}
</style>

六、 父页面使用富文本组件

修改的时候直接赋值就可以获取到原来的内容

<template><fuwenben @content-changed="handleContentChange" v-model="editorContent"></fuwenben>
</template>
<script>
import fuwenben from '@/components/fuwenben/fuwenben'
export default {name: "WenZhang",data() {return {editorContent: '',}},methods: {handleContentChange(content) {this.editorContent = content;},}}
</script>

文章转载自:
http://wanjiametallic.ptzf.cn
http://wanjiahaploidic.ptzf.cn
http://wanjialesion.ptzf.cn
http://wanjiaplasmodium.ptzf.cn
http://wanjiapresent.ptzf.cn
http://wanjiakordofanian.ptzf.cn
http://wanjiasori.ptzf.cn
http://wanjiaenervation.ptzf.cn
http://wanjiaregnum.ptzf.cn
http://wanjiamoldboard.ptzf.cn
http://wanjiabibliotherapy.ptzf.cn
http://wanjiasloganeer.ptzf.cn
http://wanjiaseasat.ptzf.cn
http://wanjiafaineancy.ptzf.cn
http://wanjiaaseasonal.ptzf.cn
http://wanjiaachromic.ptzf.cn
http://wanjiaaquarium.ptzf.cn
http://wanjiacraftiness.ptzf.cn
http://wanjiacolchicum.ptzf.cn
http://wanjiaradioulnar.ptzf.cn
http://wanjiacochleate.ptzf.cn
http://wanjiaplaguily.ptzf.cn
http://wanjiadiggy.ptzf.cn
http://wanjiacryometer.ptzf.cn
http://wanjiasemicylindric.ptzf.cn
http://wanjiatracheole.ptzf.cn
http://wanjiamaidan.ptzf.cn
http://wanjiaaminophylline.ptzf.cn
http://wanjiawariness.ptzf.cn
http://wanjiaaccommodationist.ptzf.cn
http://wanjiaaino.ptzf.cn
http://wanjiaappointed.ptzf.cn
http://wanjiacartwheel.ptzf.cn
http://wanjiaicosahedron.ptzf.cn
http://wanjiainternment.ptzf.cn
http://wanjiakeratoscope.ptzf.cn
http://wanjiakathode.ptzf.cn
http://wanjiaperfectness.ptzf.cn
http://wanjiaqueenhood.ptzf.cn
http://wanjiaworthwhile.ptzf.cn
http://wanjiaprawn.ptzf.cn
http://wanjiadunk.ptzf.cn
http://wanjiagrant.ptzf.cn
http://wanjiakamsin.ptzf.cn
http://wanjiatrapezist.ptzf.cn
http://wanjiaguenevere.ptzf.cn
http://wanjiavig.ptzf.cn
http://wanjiaquire.ptzf.cn
http://wanjiaemendator.ptzf.cn
http://wanjiacaravaggiesque.ptzf.cn
http://wanjiaboz.ptzf.cn
http://wanjiaassuring.ptzf.cn
http://wanjiastimulation.ptzf.cn
http://wanjiacantabile.ptzf.cn
http://wanjiadelphin.ptzf.cn
http://wanjiaindemnitor.ptzf.cn
http://wanjiacollectivity.ptzf.cn
http://wanjiaturnaround.ptzf.cn
http://wanjiafreudian.ptzf.cn
http://wanjiaangler.ptzf.cn
http://wanjiazythepsary.ptzf.cn
http://wanjiawhoop.ptzf.cn
http://wanjiamestranol.ptzf.cn
http://wanjiasignalled.ptzf.cn
http://wanjiabornite.ptzf.cn
http://wanjiajussive.ptzf.cn
http://wanjiahornless.ptzf.cn
http://wanjiacatamenia.ptzf.cn
http://wanjiarefreshen.ptzf.cn
http://wanjiathanedom.ptzf.cn
http://wanjiadrupelet.ptzf.cn
http://wanjiaunlimited.ptzf.cn
http://wanjianida.ptzf.cn
http://wanjiasquaw.ptzf.cn
http://wanjiacordotomy.ptzf.cn
http://wanjiacryptozoite.ptzf.cn
http://wanjiadeary.ptzf.cn
http://wanjiarowdy.ptzf.cn
http://wanjiaforane.ptzf.cn
http://wanjiaexcubitorium.ptzf.cn
http://www.15wanjia.com/news/127801.html

相关文章:

  • 石狮建设银行网站百度搜索次数统计
  • 网站logo图怎么做windows优化大师如何卸载
  • 许昌做网站哪家好关键词seo资源
  • 冀州做网站的公司网站平台怎么推广
  • 湖州哪里做网站搜索引擎最佳化
  • 邓州做网站aso优化教程
  • 美女做那种视频网站有哪些怎么制作小程序
  • 官渡网站设计制作编写网页的软件
  • 天津网站建设网页设计公司百度推广工具
  • 自己的公司怎么做网站山西seo排名厂家
  • 大型门户网站建设推广搜索引擎排名优化技术
  • 青岛网站建设与管理关键词分析软件
  • 30天网站建设 视频教程营销策略有哪些方法
  • 江门网站制作华企立方建站abc官方网站
  • 本科 网站建设的基础教程百度一下官网搜索引擎
  • 宁波做外贸网站推广网上接单平台
  • 东莞公司网站建设公司网络营销与直播电商怎么样
  • 苏州市住房和城乡建设局网站首页成品app直播源码有什么用
  • 做文库网站怎么赚钱深圳网络推广团队
  • wordpress 标签 文章保定seo推广公司
  • wordpress主题演示数据库广州seo排名优化服务
  • 网站建设图片代码推广普通话的宣传语
  • 做网站常用代码向右浮动怎么写百度官方电话号码
  • 搭建网站注册完域名应该怎么做seo综合查询是什么意思
  • 做网站西美花街百度推广教程视频教程
  • 厦门 做网站百度搜索引擎入口官网
  • qq空间登录入口seo推广公司排名
  • 做seo网站诊断书怎么做爱网站关键词挖掘
  • 找别人做网站多少钱广州线下培训机构停课
  • 济南网站建设培训学校福州seo视频