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

相关推荐
前端Hardy3 分钟前
HTML&CSS:产品卡片动画效果
前端·javascript
货拉拉技术9 分钟前
货拉拉开源:鸿蒙路由 TheRouter
android·前端·harmonyos
中杯可乐多加冰11 分钟前
工业4.0数字孪生新引擎:星图云开发者平台全景评测
前端·低代码·掘金·金石计划
云边小卖铺.17 分钟前
运行vue项目报错 errors and 0 warnings potentially fixable with the `--fix` option.
前端·javascript·vue.js
我是若尘19 分钟前
前端处理大量并发请求的实用技巧
前端
Lstmxx20 分钟前
Electron:使用数据流的形式加载本地视频
前端·electron·node.js
JunjunZ28 分钟前
unibest框架开发uniapp项目:兼容小程序问题
前端·vue.js
lyc23333330 分钟前
鸿蒙Next应用启动框架AppStartup:流程管理与性能优化🚀
前端
Data_Adventure30 分钟前
Vue 3 作用域插槽:原理剖析与高级应用
前端·vue.js
curdcv_po38 分钟前
报错 /bin/sh: .../scrcpy-server: cannot execute binary file
前端