当前位置: 首页 > news >正文

vue3 codemirror yaml文件编辑器插件

需求:前端编写yaml配置文件 ,检查yaml语法 提供语法高亮  。

默认内容从后端接口获取 显示在前端 , 前端在codemirror 插件中修改文件内容 ,并提交修改

后端将提交的内容写入服务器配置文件中 。

codemirror 通过ref 后期编辑器对象,对编辑器值(内容) 进行获取和修改操作

双向绑定数据内容 

<template>v-model="code"
</template>

ts中 动态获取后端接口数据 

编辑器默认的内容 可以通过axios 获取后端数据

<script lang="ts">const code = ref("dsadsdsadsadasdsadasddadasdasdsda");
</script">

通过ref 获取后端接口数据 

const code =ref() 
axios.post("/api/e_game_api").then(res =>{console.log("config配置文件内容")code.value = res.dataconsole.log(code.value)})return {
code 
}

完整代码:

<template><codemirrorv-model="code"placeholder="yaml编辑器":style="{height: '400px', textAlign: 'left'}":autofocus="true":indent-with-tab="true":tab-size="2":extensions="extensions"@ready="handleReady"@change="log('change',$event)"@focus="log('focus', $event)"@blur="log('blur',$event)"/></template><script lang="ts">
import {defineComponent, onMounted, ref, shallowRef} from 'vue'
// 核心库
import {Codemirror} from "vue-codemirror";
//
import {javascript} from "@codemirror/lang-javascript";
import {oneDark} from "@codemirror/theme-one-dark";
import axios from "axios";
import {editorProps} from "@tinymce/tinymce-vue/lib/es2015/main/ts/components/EditorPropTypes";// codemirror 定义初始化组件
export default defineComponent({name: "Editor",components: {Codemirror},setup(){const code = ref("");// 扩展编辑器主题颜色const extensions = [javascript(), oneDark]//const view = shallowRef();//const handleReady = (payload:any) =>{view.value = payload.view};//const  getCodemirrorStates = () => {const state = view.value.state;const ranges = state.selection.ranges;const selected = ranges.reduce((r:any, range:any) => r + range.to - range.from, 0); // 选中的值const cursor = ranges[0].anchor; // 光标const length = state.doc.length; // 代码长度const lines = state.doc.lines; // 行数};return {code,extensions,handleReady,log: console.log}}
})
onMounted(()=>{axios.get("/api/e_game_api").then(res =>{console.log("配置文件内容")const e_game_apiData = res.dataconsole.log(e_game_apiData)})})
const getValue = () => {return editorProps
}
</script><style scoped></style>

 

http://www.lryc.cn/news/301344.html

相关文章:

  • 力扣经典题:环形链表的检测与返回
  • 【web | CTF】BUUCTF [BJDCTF2020]Easy MD5
  • spring boot Mybatis Plus分页
  • elementui 中 el-date-picker 控制选择当前年之前或者之后的年份
  • GlusterFS:开源分布式文件系统的深度解析与应用场景实践
  • 第6个-滚动动画
  • 配置oracle连接管理器(cman)
  • [N-142]基于springboot,vue停车场管理系统
  • DAY53:动态规划(买股票的最佳时机)
  • 快速实现用户认证:使用Python和Flask配合PyJWT生成与解密Token的教程及示例代码
  • 外汇110:外汇做空是什么意思?如何运作?一文读懂
  • 【记录】个人博客或笔记中的数学符号设定
  • Redis Sentinel工作原理
  • GEE入门篇|遥感专业术语:理论介绍
  • react中如何做到中断diff过程和恢复
  • python:PyPDF2 从PDF文件中提取目录
  • Java 2:运算符、表达式和语句
  • 批量提取word文件中文本框内容的三种方法
  • Leecode之合并两个有序链表
  • 陶建国教授谈中西方文化的差异与交融
  • Ps:画笔选项
  • 嵌入式——Flash(W25Q64)
  • stm32:pwm output模块,记录一下我是用smt32,输出pwm波的记录--(实现--重要)
  • phpstrom创建thinkphp项目
  • 【Linux】线程同步
  • 如何在多头自注意力机制的交叉学习中引入对于物理、生理、心理世界客观规律的对照验证...
  • 智慧公厕:让智慧城市的公共厕所焕发“智慧活力”
  • vue导出word文档(图文示例)
  • 【C Primer Plus第六版 学习笔记】 第十七章 高级数据表示
  • 租用一个服务器需要多少钱?2024阿里云新版报价