vue-striveneditor.vue (1631B)
1 <template> 2 <div ref="editor"></div> 3 </template> 4 5 <script> 6 import StrivenEditor from './striveneditor'; 7 8 export default { 9 name: 'striven-editor', 10 props: { 11 toolbarHide: Boolean, 12 toolbarBottom: Boolean, 13 toolbarOptions: Array, 14 minimal: Boolean, 15 metaUrl: String, 16 extensions: Array, 17 uploadOnPaste: Boolean, 18 toolbarOptionFillColor: String, 19 placeholder: String, 20 sanitizePaste: String, 21 imageUrl: String, 22 customToolbarOption: Object, 23 activeOptionColor: String, 24 onEnter: Function, 25 value: String, 26 toolbarTemplate: Function, 27 onPaste: Function, 28 afterPaste: Function, 29 change: Function 30 }, 31 mounted() { 32 let vm = this; 33 // Create new object to avoid mutating props 34 let config = { 35 ...vm.$props, 36 toolbarTemplate: vm.toolbarTemplate && vm.toolbarTemplate() 37 }; 38 39 vm.editor = new StrivenEditor(vm.$refs.editor, config); 40 41 // Listen to input event for v-model support 42 vm.editor.body.oninput = (e) => { 43 vm.pauseUpdate = true; 44 vm.$emit('input', vm.editor.getContent()); 45 }; 46 }, 47 data() { 48 return { 49 editor: {}, 50 pauseUpdate: false 51 }; 52 }, 53 watch: { 54 value(val) { 55 // Set the editor content when not modified from within the editor 56 if (!this.pauseUpdate) { 57 this.editor.setContent(val); 58 } 59 60 this.pauseUpdate = false; 61 } 62 } 63 }; 64 </script> 65 66 <style></style>