laravel+vue项目中引入ueditor

1、把ueditor文件放在assets/js下目录中


2、把utf8-php中的其它文件复制到public下的js中


3、创建UEditor.vue 文件在ueditor/utf8-php下,写入以下代码

<template> 
    <div :id="id"></div>
</template>

<style scoped>
//引入css文件
</style>

<script>
    //引入相应的配置文件,具体路径请根据自己配置文件放置的路径以及公共组件定义的路径自行修改
    import './ueditor.config.js'
    import './ueditor.all.min.js'
    import './ueditor.parse.min.js'
    import './lang/zh-cn/zh-cn.js'

    export default {
        props: {},
        data() {
            return {
                id: Math.ceil(Math.random() * 100000) + 'editor'
            }
        },
        mounted() {
            // 获取编辑器实例化的对象
            this.editor = UE.getEditor(this.id,{
                initialFrameWidth: 700,//设置编辑器宽度
                initialFrameHeight: 700,//设置编辑器高度
                scaleEnabled: true,
            })
        },
        methods: {
            getUEContent() { // 获取内容方法
                return this.editor.getContent()
            }
        }
    }
</script>复制代码

4、在任意vue组件script标签中直接引入公共组件的UEditor.vue 文件,引入路径一定写正确


5、使用ueditor组件

<UE ref="ue" :defaultMsg='ruleForm.content'></UE>复制代码

6、调用编辑器组件的获取内容方法getUEContent()

 模版里定义一个button绑定getUEContent()方法
<button @click="getUEContent()">获取内容</button>
复制代码

7、注册getUEContent()方法:

methods: {
  getUEContent() {
    let content = this.$refs.ue.getUEContent();//在这里调用了子组件ueditor组件的getContent()方法
    this.$notify({
      title: '获取成功,可在控制台查看!',
      message: content,
      type: 'success'
    });
    console.log(content)
  }}
复制代码



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值