bin-editor-next实现josn序列化

线上链接 BIN-EDITOR-NEXThttps://wangbin3162.gitee.io/bin-editor-next/#/editor

gitee地址bin-editor-next: ace-editor 的vue3升级版本https://gitee.com/wangbin3162/bin-editor-next#https://gitee.com/link?target=https%3A%2F%2Funpkg.com%2Fbin-editor-next%2F

实现效果

安装步骤

npm 安装

推荐使用npm安装,它能更好地和webpack打包工具配合使用。而且可以更好的和 es6配合使用。并且支持按需引入

复制代码
npm i bin-editor-next -S
# or 
yarn add bin-editor-next

引入

在 main.js 中写入以下内容:

复制代码
import { createApp } from 'vue'
import Editor from 'bin-editor-next';
import App from './App.vue';

import * as ace from 'brace'
import 'brace/ext/emmet'
import 'brace/ext/language_tools'
import 'brace/mode/json'
import 'brace/snippets/json'
import 'brace/theme/chrome'

const app = createApp(App)
app.component(Editor.name, Editor)
app.mount('#app', true)

使用

parameter.value = JSON.stringify(JSON.parse(row.value), null, 2)

html 复制代码
 <!-- 修改 -->
    <el-dialog :title="title" v-model="editDialog" width="30%" draggable>
      <b-ace-editor v-model="parameter" height="400"></b-ace-editor>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel" size="default">取 消</el-button>
          <el-button type="primary" @click="onSubmit" size="default">确定</el-button>
        </span>
      </template>
    </el-dialog>
javascript 复制代码
// 编辑器JSON字符串变量
const parameter = ref()

// 打开修改角色弹窗
const currentRow = ref()
const onOpenEditRole = (row: any) => {
  editDialog.value = true;
  title.value = '设备驱动修改窗口'
  parameter.value = []
  parameter.value = toRaw(row.options)
  currentRow.value = tableData.value.findIndex((item: any) => item === row);
};

const onSubmit = async () => {
  let tablebasic = toRaw(tableData.value)
  tablebasic[currentRow.value].options = parameter.value
  await postDeviceAddSave(tablebasic)
  await getTableData()  //刷新页面
  editDialog.value = false;
}

提示报错添加文件 src中添加 type.d.ts :declare module "bin-editor-next";

相关推荐
风骏时光牛马1 小时前
后端服务接口开发与性能优化
前端
kyriewen1 小时前
我让 4 个 AI 互相 review 代码,最温柔的那个下手最狠
前端·程序员·ai编程
计算机魔术师2 小时前
493家公司白砸AI钱?Apollo这组数据戳破了幻觉
前端
IT_陈寒2 小时前
Java静态变量初始化坑得我头皮发麻
前端·人工智能·后端
柳杉2 小时前
用 Codex 完成智慧高速 3D 可视化大屏,从 18 张行业设计稿到可交互的运行监测中心
前端·ai编程·数据可视化
review445432 小时前
拿到 codex 第一步
前端·agent·vibecoding
鶴哥只手遮天3 小时前
jQuery 4.0 源码架构与工程实践-第 01 章 · 全景与工程结构:一个 20 岁库的自省
前端·javascript·jquery
徐小夕3 小时前
doc2docx方案,开源!
前端·vue.js·github
徐小夕3 小时前
JitOFD:一款面向信创与档案场景的 Web 端 OFD 编辑器
前端·vue.js·github
孟健4 小时前
Kimi K3.1 Pro 编程实测:3个月27万行代码,每年1.7万预算下如何9分钟修好顽固Bug
前端·开源·ai编程