From ebe0554c3af2a6a4a8a8bd86b135cc4717f8e91c Mon Sep 17 00:00:00 2001 From: liudianxin Date: Mon, 31 Aug 2020 17:12:00 +0800 Subject: [PATCH] =?UTF-8?q?json=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/general/codes.vue | 30 +++++++++++++--------- src/pages/workbench/fwgl/serviceDetail.vue | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/components/general/codes.vue b/src/components/general/codes.vue index 1eb47f2..870e38f 100644 --- a/src/components/general/codes.vue +++ b/src/components/general/codes.vue @@ -17,12 +17,17 @@ import ace from "ace-builds"; import "ace-builds/webpack-resolver"; // 在 webpack 环境中使用必须要导入 import "ace-builds/src-noconflict/mode-json"; // 默认设置的语言模式 export default { - props: ["url","datas",'readOnly'], + props: { + url: { + type: String, + default: "", + }, + datas: { type: String, default: "" }, + readOnly: { type: Boolean, default: false }, + }, data() { return { aceEditor: null, - themePath: "ace/theme/monokai", // 不导入 webpack-resolver,该模块路径会报错 - modePath: this.acemodePath }; }, @@ -31,17 +36,18 @@ export default { maxLines: 24, minLines: 10, fontSize: 14, - mode: this.acemodePath, - wrap: this.wrap, - tabSize: 4, + wrap: true, + tabSize: 2, highlightActiveLine: false, - readOnly:this.readOnly?this.readOnly:false + readOnly: this.readOnly, }); if (this.url) { this.getValue(); } if (this.datas) { - this.aceEditor.setValue(this.datas); + this.aceEditor.setValue( + JSON.stringify(JSON.parse(this.datas), null, "\t") + ); } }, watch: {}, @@ -49,10 +55,10 @@ export default { getValue() { this.$http .get(this.url) - .then(response => { + .then((response) => { this.aceEditor.setValue(response.data); }) - .catch(function(response) { + .catch(function (response) { console.log(response); }); }, @@ -61,8 +67,8 @@ export default { }, getCodesVal() { return this.aceEditor.getValue(); - } - } + }, + }, };