18910140161

小tips:vue与百度UEditor富文本编辑器相结合 实现vue-ueditor-wrap

顺晟科技

2021-08-04 10:53:26

307

1.下载vue-ueditor-wrap

cnpm i vue-ueditor-wrap -S

下载最新的 UEditor 资源文件放入你项目的静态资源目录中(比如 static 或者 public,这取决于你项目的配置)。

2.引入VueUeditorWrap组件

import VueUeditorWrap from \'vue-ueditor-wrap\'

3.注册组件

components: {
  VueUeditorWrap
}
// 或者在 main.js 里将它注册为全局组件
Vue.component(\'vue-ueditor-wrap\', VueUeditorWrap)

4.v-model绑定数据

<vue-ueditor-wrap v-model="msg"></vue-ueditor-wrap>

5.示例

<template>
  <div class="hello">
    <vue-ueditor-wrap ref="ueditor" v-model="msg" :destroy="false" :config="config" style="width: 600px;margin: 0 auto;"></vue-ueditor-wrap>
    <button @click="showData" class="preview">保存内容</button>
  </div>
</template>

<script>
import VueUeditorWrap from \'vue-ueditor-wrap\' // ES6 Module
export default {
  name: \'HelloWorld\',
  components: {
    VueUeditorWrap
  },
  data () {
    return {
      msg: \'请输入内容\',
      config: {
        // 编辑器不自动被内容撑高
        autoHeightEnabled: true,
        // 初始容器高度
        initialFrameHeight: 240,
        elementPathEnabled: false,
        wordCount: false,
        enableAutoSave: false,
        // 初始容器宽度
        initialFrameWidth: \'\',
        serverUrl: \'\'
      }
    }
  },
  mounted () {

  },
  methods: {
    showData () {
      console.log(this.msg)
    }
  }
}
</script>

详细的配置可参考UEditor富文本编辑器官网。

参考地址

  • UEditor富文本编辑器
  • vue-ueditor-wrap github地址
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航