using summernote with vue.js 2

后端 未结 1 1927
灰色年华
灰色年华 2021-01-14 14:30

i want to use summernote in my vue.js 2 spa, and because not all my page using summernote so i make summernote to be a component by adding

export default {
         


        
相关标签:
1条回答
  • I answered here since comments are not very good at displaying code.

    <template>
    <div id="app">
      <summernote
        name="editor"
        :model="content"
        v-on:change="value => { content = value }"
      ></summernote>
    </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
            content: null   
        }
      },
      components: {
        'summernote' : require('./Summernote')
      }
    }
    </script>
    

    I think you can use the summernote module in this way.
    I looked into the source code. It's quite simple and short since it's just a wrapper of summernote.

    Update
    I forked the project and changed some code to make it easier to set summernote's configuration and plugins. With this version, you can pass your configuration as an object prop. You can also add a plugin by importing it in html script tag.
    See sample code below.

    <template>
    <div id="app">
      <summernote
        name="editor"
        :model="content"
        v-on:change="value => { content = value }"
        :config="config"
      ></summernote>
    </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
            content: null,
            // ↓ It is what the configuration object looks like. ↓
            config: {
                height: 100,
                toolbar: [
                    // [groupName, [list of button]]
                    ['style', ['bold', 'italic', 'underline', 'clear']],
                    ['font', ['strikethrough', 'superscript', 'subscript']],
                    ['fontsize', ['fontsize']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['insert', ['gxcode']], // plugin config: summernote-ext-codewrapper
              ],
            }, 
        }
      },
      components: {
        'summernote' : require('./Summernote')
      }
    }
    </script>
    

    I wish you could get my idea. You can also look into the forked project for more information.

    0 讨论(0)
提交回复
热议问题