vue.js集成codeMirror代碼編輯器的詳細代碼
更新時間:2025年05月09日 10:01:30 作者:renpingsheng788
這篇文章主要介紹了vue.js集成codeMirror代碼編輯器的相關資料,代碼分為前端代碼和后端代碼,感興趣的朋友一起看看吧
1.前端代碼
<link rel="external nofollow" 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('添加內(nèi)容成功');
} else {
this.$message.error('添加內(nèi)容失敗');
}
}, 'json');
}
}
})
</script>2.后端代碼
def create_blog(request):
data = json.loads(request.body)
content = data.get("content")
print(content)
...
return JsonResponse({"result": True})顯示效果

到此這篇關于vue.js集成codeMirror代碼編輯器的文章就介紹到這了,更多相關vue.js codeMirror代碼編輯器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Element-plus表格數(shù)據(jù)延遲加載的實現(xiàn)方案
本文介紹了在前端展示大量數(shù)據(jù)時遇到的加載卡頓問題,并提供了一種解決方案:延遲加載,具體做法是設置加載數(shù)量,對于數(shù)據(jù)量較大的情況,進行分批加載數(shù)據(jù),通過類選擇器找到表格滾動條并進行監(jiān)聽綁定事件,感興趣的朋友跟隨小編一起看看吧2024-11-11
VUE父組件異步獲取數(shù)據(jù),子組件接收的值為空的問題
這篇文章主要介紹了VUE父組件異步獲取數(shù)據(jù),子組件接收的值為空的問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
利用vue+elementUI實現(xiàn)部分引入組件的方法詳解
這篇文章主要給大家介紹了關于利用vue+elementUI實現(xiàn)部分引入組件的相關資料,以及介紹了vue引入elementUI報錯的解決方法,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧。2017-11-11
vue.config.js配置proxy代理產(chǎn)生404錯誤的原因及解決
這篇文章主要介紹了vue.config.js配置proxy代理產(chǎn)生404錯誤的原因及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06

