uniapp富文本的使用

<editor class="richInputContent" id="editor" @input="getEditorContent" @ready="onEditorReady" v-model="html"></editor>


methods:{
      //初始化富文本编辑器
            onEditorReady() {
                    uni.createSelectorQuery().select('#editor').context((res) => {
                    var contentVal_1 = this.content;
                    //将内容写入编辑器
                    this.editorCtx = res.context;
                    let EContent = {
                        html: contentVal_1
                    }
                    this.editorCtx.setContents(EContent);
                }).exec()
            },

            getEditorContent(e) {
                this.content = e.detail.html;
                this.contentText = e.detail.text;
            },

            //上传图片
            uploadImg(index) {
                let that = this
                uni.chooseImage({
                    count: 1,
                    success: function(res) {
                        let url = res.tempFilePaths[0]
                        console.log(res)
                        uni.uploadFile({
                            url: 'https://nmssafety.51yunmai.com/FileUpload/FileUploadMobile',
                            filePath: url,
                            name: 'Data',
                            formData: {
                                token: uni.getStorageSync("token")
                            },
                            success: (res) => {
                                console.log(res)
                                that.editorCtx.insertImage({
                                    src: JSON.parse(res.data).ImageUrl,
                                    alt: '图像',
                                    success: function() {}
                                })
                            }
                        });
                    },

                })
            },

}    

editorContext.format(name, value)  修改富文本样式

更多查看该链接https://uniapp.dcloud.io/api/media/editor-context?id=editorcontextformat

posted @ 2022-12-22 16:58  蓦然JL  阅读(1723)  评论(0编辑  收藏  举报
访问主页
关注我
关注微博
私信我
返回顶部