123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <template>
- <div class="rich-text"></div>
- </template>
- <script>
- import { renderRichText } from "./vEditor/renderJSON";
- export default {
- name: "RichText",
- props: {
- textJson: {
- type: [String, Object],
- default() {
- return { sections: [] };
- },
- },
- },
- data() {
- return {};
- },
- watch: {
- textJson(val) {
- this.renderVal(val);
- },
- },
- mounted() {
- this.renderVal(this.textJson);
- },
- methods: {
- getJson(val) {
- let json = null;
- try {
- json = JSON.parse(val);
- } catch (e) {
- console.log("not json");
- }
- return json;
- },
- renderVal(val) {
- if (typeof textJson === "string") {
- this.$el.innerHTML = val;
- } else {
- renderRichText(val, this.$el);
- }
- },
- },
- };
- </script>
|