1、添加less 和less-loader支持

npm install less less-loader --save-dev

2、新建main.less,将这个样式添加到home.vue中的content标签上(添加之后页面可滚动)

.content-wrapper{
padding: 18px;
height: ~"calc(100% - 80px)";
overflow: auto;
}

3、main.less需要在home.vue中引入

 import '../main.less'

4、添加富文本编辑

https://liubing.me/vue-tinymce-5.html

npm install @tinymce/tinymce-vue -S
npm install tinymce -S

5、创建edit-post.vue

<template>
<div class="editor">
<TinymceEditor ref="editor" v-model="content" :disabled="disabled" @onClick="onClick"></TinymceEditor>
</div>
</template> <script>
import TinymceEditor from '@/components/tinymce-editor' export default {
name: "EidtPost",
components: {
TinymceEditor
},
data() {
return {
content: 'Welcome to Use Tinymce Editor',
disabled: false
}
},
methods: {
// 鼠标单击的事件
onClick(e, editor) {
console.log('Element clicked')
console.log(e)
console.log(editor)
},
// 清空内容
clear() {
this.$refs.editor.clear()
}
}
}
</script> <style scoped>
.editor {
padding: 20px;
height: 100%;
margin-left: 10%;
margin-right: 10%;
} </style>

6、创建tinymce-editor.vue

<template>
<div class="tinymce-editor">
<editor v-model="myValue" :init="init" :disabled="disabled" @onClick="onClick">
</editor>
</div>
</template>
<script>
import tinymce from 'tinymce/tinymce'
import Editor from '@tinymce/tinymce-vue'
import 'tinymce/themes/silver'
// 编辑器插件plugins
// 更多插件参考:https://www.tiny.cloud/docs/plugins/
import 'tinymce/plugins/image'// 插入上传图片插件
import 'tinymce/plugins/media'// 插入视频插件
import 'tinymce/plugins/table'// 插入表格插件
import 'tinymce/plugins/lists'// 列表插件
import 'tinymce/plugins/wordcount'// 字数统计插件
export default {
components: {
Editor
},
props: {
value: {
type: String,
default: ''
},
disabled: {
type: Boolean,
default: false
},
plugins: {
type: [String, Array],
default: 'lists image media table wordcount autoresize'
},
toolbar: {
type: [String, Array],
default: 'undo redo | formatselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists image media table | removeformat'
}
},
data () {
return {
init: {
language_url: '/static/tinymce/langs/zh_CN.js',
language: 'zh_CN',
skin_url: '/static/tinymce/skins/ui/oxide',
// skin_url: '/tinymce/skins/ui/oxide',//暗色系
height: document.body.clientHeight * 0.8,
plugins: this.plugins,
toolbar: this.toolbar,
branding: false,
menubar: false,
// 此处为图片上传处理函数,这个直接用了base64的图片形式上传图片,
// 如需ajax上传可参考https://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_handler
images_upload_handler: (blobInfo, success, failure) => {
const img = 'data:image/jpeg;base64,' + blobInfo.base64()
success(img)
}
},
myValue: this.value
}
},
mounted () {
tinymce.init({})
},
methods: {
// 添加相关的事件,可用的事件参照文档=> https://github.com/tinymce/tinymce-vue => All available events
// 需要什么事件可以自己增加
onClick (e) {
this.$emit('onClick', e, tinymce)
},
// 可以添加一些自己的自定义事件,如清空内容
clear () {
this.myValue = ''
}
},
watch: {
value (newValue) {
this.myValue = newValue
},
myValue (newValue) {
this.$emit('input', newValue)
}
}
} </script> <style scoped>
.editor {
padding: 20px;
height: 100%;
margin-left: 10%;
margin-right: 10%;
} </style>

页面显示:

下一篇:https://www.cnblogs.com/nxzblogs/p/10923014.html

vue - blog开发学习3的更多相关文章

  1. vue - blog开发学习5

    基本功能和后台联调 1.首页的所有博客 因为是前后台都是本地开发,所以前端vue需要设置proxy:修改/config/index.js中的这个proxyTable proxyTable: { '/a ...

  2. vue - blog开发学习2

    首页博客列表的开发 1.修改index.vue,使能够支持列表功能 <template> <div> <PostList v-for="(item,index) ...

  3. vue - blog开发学习1

    1.安装vue-cli vue intall -g vue-cli 2.创建项目 vue init webpack nblog 3.按提示要求配置项目 ? Project name nblog ? P ...

  4. vue - blog开发学习6

    1.问题,如下图,使用iviewui中的card导致页面不能出现滚动条(不太会弄,在网上查了一个vue组件vuescroll,因此使用这个做滚动条) 2.安装vuescroll cnpm instal ...

  5. vue - blog开发学习4

    1.新建页面的修改,集成富文本编辑 edit-post.vue(新建和修改都用该组件) <template> <div class="editor"> &l ...

  6. vue - blog开发学7

    将基本的项目部署到linux上(前后台只是实现了基本的功能,本次只是记录一些基本的开发流程,完善,等后续) 1.linux环境准备(我用的是阿里云服务器) ①jre.mysql,Nginx基本上这些就 ...

  7. Vue学习笔记-Vue.js-2.X 学习(二)===>组件化开发

    ===重点重点开始 ========================== (三) 组件化开发 1.创建组件构造器: Vue.extends() 2.注册组件: Vue.component() 3.使用 ...

  8. 前端开发 Vue -1windows环境搭建Vue Node开发环境

    解决几个疑问: 想学习下vue.js,我理解的它是一个前端的框架,主要作用是对数据的处理,和juqery类似,所以不太理解为什么要在nodejs中npm install vue呢?在html文件中引入 ...

  9. Android开发学习路线图

    Android开发学习方法: Android是一个比较庞大的体系,从底层的Linux内核到上层的应用层,各部分的内容跨度也比较大.因此,一个好的学习方法对我们学习Android开发很重要. 在此建议, ...

随机推荐

  1. C++中类的静态成员变量

    1,成员变量的回顾: 1,通过对象名能够访问 public 成员变量: 2,每个对象的成员变量都是专属的: 3,成员变量不能在对象之间共享: 1,在做程序设计中,成员变量一般是私有的.至少不是公有的: ...

  2. 关于GeneXus封装方法Model的方法

     最近 刚从外地出差回来 工作任务不是很重 能够抽点时间记点东西 下午花了2个多钟头尝试了一下GeneXus的封装方法的功能,这里记一下便于自己以后查看.我们在许多项目中或多或少都会有着重复代码编写的 ...

  3. 后台执行循环(done &)

  4. go语言从例子开始之Example1.helloworld

    Example: package main import "fmt" func main() { fmt.Println("hello world") } Re ...

  5. 转载:jQuery的deferred对象详解

    一.什么是deferred对象? 开发网站的过程中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数据),也有同步的操作(比如遍历一个大型数组),它们 ...

  6. mongodb使用本地日期查询

    db.getCollection('userLog').find({createAt:{"$gt":new Date("2018-08-05"),"$ ...

  7. jvm主要组成部分及其作用

    1.类加载器(Class Loader):加载类文件到内存.Class loader只管加载,只要符合文件结构就加载,至于能否运行,它不负责,那是有Exectution Engine 负责的. 2.执 ...

  8. Spring AOP中的JDK和CGLIB动态代理

    Spring在将Advice织入目标对象的Joinpoint是在运行时动态进行的.它采用的方式可能有两种,即JDK动态代理与CGLIB代理.Spring会根据具体的情况在两者之间切换. 实际情况如下: ...

  9. Springboot 拦截器配置(登录拦截)

    Springboot 拦截器配置(登录拦截) 注意这里环境为springboot为2.1版本 1.编写拦截器实现类,实现接口   HandlerInterceptor, 重写里面需要的三个比较常用的方 ...

  10. POJ 3904 (莫比乌斯反演)

    Stancu likes space travels but he is a poor software developer and will never be able to buy his own ...