npm 安装
npm i bin-code-editor -S # or yarn add bin-code-editor
引入
在 main.js 中写入以下内容:
import Vue from 'vue'; import CodeEditor from 'bin-code-editor'; import 'bin-code-editor/lib/style/index.css'; import App from './App.vue'; Vue.use(CodeEditor); new Vue({ el: '#app', render: h => h(App) });
示例代码
<template> <div> <b-code-editor v-model="jsonStr" :indent-unit="4" height="auto"/> </div> </template> <script> const jsonData = `{"title":"测试json数据","children":[{"name":"子项名称", "desc":"子项说明" },{"name":"子项名称1", "desc":"子项说明1" }]}` export default { data() { return { jsonStr: jsonData } } } </script>
refer:
https://wangbin3162.gitee.io/bin-code-editor/#/guide