Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration for VueJs #555

Closed
makenskiy opened this issue Dec 24, 2018 · 3 comments
Closed

Integration for VueJs #555

makenskiy opened this issue Dec 24, 2018 · 3 comments

Comments

@makenskiy
Copy link

Hi, this example for VueJS. May be need for community. I's work for me.

Componet editor

<template>
    <article>
        <textarea :id="id"></textarea>
    </article>
</template>

<script>
    import SirTrevor from 'sir-trevor/build/sir-trevor';
    import icon from 'sir-trevor/build/sir-trevor-icons.svg';

    export default {
        name: 'c-editor',
        props: {
            id: {
                type: String,
                default: 'js-st-instance'
            }
        },
        data() {
            return {
                el: null,
                editor: null
            };
        },
        methods: {
            save() {
                this.editor.onFormSubmit();
            },
            update(value) {
                this.el.value = value;
                this.editor.reinitialize();
            }
        },
        mounted() {
            this.el = document.getElementById(this.id);
            if (!this.el) return false;
            this.editor = new SirTrevor.Editor({
                el: this.el,
                defaultType: ['Text', 'Image'],
                 iconUrl: icon
            });
        }
    };
</script>

Page

<template>
    <div>
        ....................... other form ......................
        <c-editor ref="editor"></c-editor>
        <b-button @click="bSave()">
            Save
        </b-button>
    </div>
</template>

<script>
    export default {
        data() {
            return {};
        },
        methods: {
            bSave() {
                if (this.$refs.editor) {
                    this.$refs.editor.save();
                    this.model._data.text.ru = JSON.stringify(this.$refs.editor.editor.store.retrieve());
                }
            }
        },
        updated() {
            if (this.$refs.editor) this.$refs.editor.update(this.model._data.text);
        }
    };
</script>

I not found event "watch live data" to make this.$emit() simple code.

@raffij
Copy link
Contributor

raffij commented Dec 24, 2018

This is the correct way to get and restore data for now.

@raffij
Copy link
Contributor

raffij commented Dec 24, 2018

I also saw someone had submitted a couple of prs:

editor.restore(data) and editor.getData() which does what you are looking for so i'll merge those into the next release.

@makenskiy
Copy link
Author

Thank. It will be wonderful.

@raffij raffij closed this as completed Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants