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

相关推荐
前端之虎陈随易4 小时前
编程语言级别的Skill市场,AI Agent 的未来形态
前端·vue.js·人工智能·typescript·node.js
一路向北he4 小时前
字节钢铁军团--“提供情境,而非控制”
java·开发语言·前端
kyriewen4 小时前
豆包和千问同时关了智能体,我用它们搭的 3 个自动化全废了——迁移方案整理
前端·javascript·ai编程
前端一小卒4 小时前
我用 TypeScript 从零手写了一个 Claude Code,然后发现它的核心只有 30 行
前端·agent
大圣编程6 小时前
Python中continue语句的用法是什么?
开发语言·前端·python
yuhaiqiang6 小时前
随手 vibecoding 的浏览器插件已经 6000 多次下载,聊聊他的产品设计
前端·后端·面试
之歆6 小时前
Vue商品详情与放大镜组件
前端·javascript·vue.js
再吃一根胡萝卜7 小时前
如何把小米 MiMo 接入 CodeBuddy,打造私有 Agent
前端
负责的蛋挞8 小时前
异步HttpModule的实现方式
java·服务器·前端