zoukankan      html  css  js  c++  java
  • vue.js集成codeMirror代码编辑器

    1.前端代码

    <link href="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.js"></script>
    <script src="https://cdn.bootcss.com/codemirror/5.48.4/mode/python/python.js"></script>
    
    <div id="app" style="margin-top: 60px;">
        <el-row :gutter="40">
            <el-col :span="20" :offset="2">
                <div style="border: 1px solid #ddd;" id="div1">
                    <textarea id="editor_demo"></textarea>
                </div>
            </el-col>
            <el-col :span="2" :offset="20" style="margin-top: 20px;">
                <el-button type="primary" @click="handleAdd">添加</el-button>
            </el-col>
        </el-row>
    </div>
    
    <script type="text/javascript">
        new Vue({
            el: '#app',
            data: {
                editor: null
            },
            mounted() {
                this.init()
            },
            methods: {
                init() {
                    this.editor = CodeMirror.fromTextArea(document.getElementById("editor_demo"), {
                      lineNumbers: true,
                      indentWithTabs: true,
                      mode: "python",
                      matchBrackets: true
                    });
                    this.editor.setSize('auto','600px');
                },
                handleAdd() {
                    axios.post(site_url + "create_blog/", {"content": this.editor.getValue()}).then(res => {
                        if (res.data.result) {
                            this.$message.success('添加内容成功');
                        } else {
                            this.$message.error('添加内容失败');
                        }
                    }, 'json');
                }
            }
        })
    </script>
    

    2.后端代码

    def create_blog(request):
        data = json.loads(request.body)
        content = data.get("content")
        print(content)
        ...
        return JsonResponse({"result": True})
    

    显示效果

  • 相关阅读:
    欧拉路问题
    树上依赖背包总结
    树状数组的应用
    KMP
    深探树形dp
    再探树形dp
    日常水题
    深入hash
    同一控制下的企业合并,长期股权投资成本与支付账面之间的差额计入资本公积
    资本公积冲减留存收益
  • 原文地址:https://www.cnblogs.com/renpingsheng/p/11777017.html
Copyright © 2011-2022 走看看