akaunting/resources/assets/js/components/AkauntingHtmlEditor.vue

88 lines
1.9 KiB
Vue
Raw Normal View History

<template>
2022-06-01 10:15:55 +03:00
<div>
<vue-editor :id="editorId" v-model="content" :editorToolbar="customToolbar" :disabled="disabled"></vue-editor>
</div>
</template>
<script>
2022-06-01 10:15:55 +03:00
import { VueEditor } from "vue2-editor";
export default {
name: 'akaunting-html-editor',
2022-06-01 10:15:55 +03:00
components: {
VueEditor
},
props: {
2022-06-01 10:15:55 +03:00
name: {
type: String,
default: '',
description: 'The name of the field',
},
value: {
type: String,
default: ''
},
2022-06-01 10:15:55 +03:00
model: {
type: [String, Number, Array, Object],
default: '',
description: "Selectbox selected model"
},
2022-06-01 10:15:55 +03:00
disabled: {
2021-04-07 17:53:54 +03:00
type: Boolean,
2022-06-01 10:15:55 +03:00
default: false,
description: "Selectbox disabled status"
2021-04-07 17:53:54 +03:00
},
},
data () {
return {
content: null,
editorId: null,
2022-06-01 10:15:55 +03:00
customToolbar: [
["bold", "italic", "underline"],
[{ list: "ordered" }, { list: "bullet" }],
],
}
},
methods: {
randomString() {
let text = "";
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (let i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
},
},
async mounted () {
this.editorId = this.randomString();
2022-06-01 10:15:55 +03:00
this.content = this.value;
},
watch: {
value (newVal) {
if (newVal !== this.content) {
2022-06-01 10:15:55 +03:00
this.content = newVal;
}
},
2022-06-01 10:15:55 +03:00
model (newVal) {
if (newVal !== this.content) {
2022-06-01 10:15:55 +03:00
this.content = newVal;
}
},
content (newVal) {
this.$emit('input', newVal);
},
},
}
</script>