vue.js集成codeMirror代碼編輯器的詳細(xì)代碼
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})顯示效果

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

