首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带vuejs的trumbowyg编辑器

带vuejs的trumbowyg编辑器
EN

Stack Overflow用户
提问于 2016-12-21 19:32:08
回答 1查看 896关注 0票数 0

我在我的vuejs水疗中心使用三轮车编辑器控件。在文献资料中,我知道我可以使用以下代码来设置编辑器的内容。

代码语言:javascript
复制
$('#editor').trumbowyg('html','<p>Your content here</p>'); 
$('#editor').trigger('tbwchange');

然而,在我的VueJs应用程序中,它并不适用于我。我有一个定义了描述键的对象。我可以console.log描述,但是当我试图将它分配给上面提到的编辑器控件时,它会失败。我在console中没有看到错误,但是文本不会出现在编辑器中。

这是我现在要做的事。

代码语言:javascript
复制
<template>
    <div class="modal fade"  data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">
                        <span v-if="anouncement">Edit Anouncement</span>
                        <span v-else>New Anouncement</span>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <input type="text" placeholder="enter anouncement summary here" class="form-control" v-model="anouncementObj.summary">
                    </div>
                    <div class="form-group">
                        <input type="text" placeholder="enter location here" class="form-control" v-model="anouncementObj.location">
                    </div>
                    <textarea class="note-view__body" id="anonDescription" v-model="description" placeholder="enter event description"></textarea>
                </div>
                <div class="modal-footer">
                    <button type="button" v-on:click="clear()" class="btn btn-link" data-dismiss="modal">Close</button>
                    <button type="button" v-on:click="performSave()" class="btn btn-link">Save</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props : {
            anouncement : Object
        },
        data() {
            return {
                anouncementObj :{}
            }
        },
        mounted () {
            this.makeTextBoxReady();
            this.anouncementObj = Object.assign({},this.anouncementObj, this.anouncement || {});
                $('#anonDescription').trumbowyg('html',this.anouncement.description); 
                $('#anonDescription').trigger('tbwchange');
                console.log(this.anouncement.description);
        },
        methods : {
            makeTextBoxReady: function() {
                $(document).ready(function() {
                    if (!$('html').is('.ie9')) {
                        if ($('.note-view__body')[0]) {
                            $('.note-view__body').trumbowyg({
                                autogrow: true,
                                btns: [
                                    'btnGrp-semantic', ['formatting'],
                                    'btnGrp-justify',
                                    'btnGrp-lists', ['removeformat']
                                ]
                            });
                        }
                    }
                });
            },
            performSave : function() {
                let description = $('#anonDescription').trumbowyg('html');

                let formData = new FormData();
                for (name in this.anouncementObj) {
                    formData.append(name, this.anouncementObj[name]);
                }

                if( !this.anouncementObj.id) {
                    this.anouncementObj.id = 0;
                }

                formData.append('description',description);

                this.$http.post('/admin/anouncement/createOrUpdate', formData).then(response => {
                    // console.log(response);
                    if(response.data.status==200) {
                        alert(response.data.message);
                        this.$emit('getAnouncements');
                    }
                })
            },
            clear: function() {
                this.anouncementObj= {};
            }

        }
    }
</script>

你能告诉我我在这里做错了什么吗?我也尝试过nexttick方法,但即使这样也不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-25 05:21:03

我让它起作用了。我没有使用正确的引导模式标识。有关更多信息,请参阅此相关问题

这是正确的代码。

代码语言:javascript
复制
if(this.anouncementObj && this.anouncementObj.description && this.anouncementObj.id) {
   $('#'+this.anouncementObj.id+' #anonDescription').trumbowyg('html',this.anouncementObj.description); 
   $('#'+this.anouncementObj.id+' #anonDescription').trigger('tbwchange');
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41270563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档