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";

相关推荐
上单带刀不带妹10 分钟前
ES6 中的 Proxy 全面讲解
前端·ecmascript·es6·proxy
11054654011 小时前
37、需求预测与库存优化 (快消品) - /供应链管理组件/fmcg-inventory-optimization
前端·信息可视化·数据分析·js
nunumaymax1 小时前
在图片没有加载完成时设置默认图片
前端
OEC小胖胖2 小时前
【React 设计模式】受控与非受控:解构 React 组件设计的核心模式
前端·react.js·设计模式·前端框架·web
你怎么知道我是队长2 小时前
C语言---编译的最小单位---令牌(Token)
java·c语言·前端
一枚前端小能手3 小时前
🔥 Vue状态管理越写越乱,Pinia拯救了我
前端
cloudcruiser3 小时前
Apache HTTP Server:深入探索Web世界的磐石基石!!!
前端·其他·http·apache
一个专注api接口开发的小白3 小时前
手把手教程:使用 Postman 测试与调试淘宝商品详情 API
前端·数据挖掘·api
织_网4 小时前
Electron 核心 API 全解析:从基础到实战场景
前端·javascript·electron
vvilkim4 小时前
深入理解 Spring Boot Starter:简化依赖管理与自动配置的利器
java·前端·spring boot