宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

monaco-editor 簡單使用

管理 管理 編輯 刪除

ba9dd20230218174428131.png

一. 文件調(diào)用示例


1. 安裝package包 官方文檔

"monaco-editor": "^0.28.1",
"monaco-editor-webpack-plugin": "^4.2.0",

請注意安裝包的版本號

monaco-editor-webpack-pluginmonaco-editor
7.*.*>= 0.31.0
6.*.*0.30.*
5.*.*0.29.*
4.*.*0.25.*, 0.26.*, 0.27.*, 0.28.*
3.*.*0.22.*, 0.23.*, 0.24.*
2.*.*0.21.*
1.9.*0.20.*
1.8.*0.19.*
1.7.*0.18.*

2.配置vue.coinfig.js

在vue.coinfig.js中增加如下配置:

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
  lintOnSave: false,  
  configureWebpack: {
    plugins: [
      // 配置JS在線代碼編輯器monaco-editor的輔助文件
      new MonacoWebpackPlugin(),
    ],
  },
};

3. 調(diào)用示例

import * as monaco from 'monaco-editor';
export default {
  
  data() {
    return {
      monacoEditor: null, // 語言編輯器
    }
  },

  mounted(){
    this.init()
  },

  methods: {
    init(){
      if(this.$refs.codeContainer){
        // 初始化編輯器,確保dom已經(jīng)渲染
        this.monacoEditor = monaco.editor.create(this.$refs.codeContainer, {
            value: '', // 編輯器初始顯示文字
            language: 'json', // 語言
            automaticLayout: true, // 自動布局
            theme: 'vs', // 官方自帶三種主題vs, hc-black, or vs-dark
            minimap: { // 關(guān)閉小地圖
              enabled: false,
            },
            lineNumbers: 'off', // 隱藏控制行號
        });
      }
    }
  }
}

.coder-editor{
  width: 100%;
  height: 160px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

二. 屬性說明

{
    value: '', // 編輯器初始顯示文字
    language: 'javascript', // 語言javascript | json
    automaticLayout: true, // 自動布局
    theme: 'vs', // 官方自帶三種主題vs, hc-black, or vs-dark
    foldingStrategy: 'indentation', // 代碼可分小段折疊
    overviewRulerBorder: false, // 不要滾動條的邊框
    lineNumbers: 'off', // 控制行號的出現(xiàn)on | off
    scrollbar: { // 滾動條設(shè)置
      verticalScrollbarSize: 4, // 豎滾動條
      horizontalScrollbarSize: 6, // 橫滾動條
    },
    readOnly: false, // 是否只讀 Defaults to false | true
    minimap: { // 關(guān)閉小地圖
      enabled: false,
    },
    cursorStyle: 'line', // 光標樣式
    automaticLayout: false, // 自動布局
    fontSize: 14, // 字體大小
    tabSize: 2, // tab縮進長度
    autoIndent: true, // 自動布局
}

支持的語言類型

在項目的node_modules/monaco-editor/min/vs/basic-languages目錄下能看到支持的語言類型:

三. 常用事件

銷毀編輯器

this.monacoEditor.dispose();

實時獲取編輯器的值

this.monacoEditor.onDidChangeModelContent(() => {
  this.monacoEditor.getValue() // 獲取編輯器中的語句
})

設(shè)置編輯器的值

this.monacoEditor.setValue(newValue)

其它事件

editor.setValue('console.log("Hello world!");');    //設(shè)置值
editor.getValue();  //獲取值

editor.getSelection();  //獲取選中的行信息

editor.getModel().getLineContent(1);    //獲取某一行的內(nèi)容
editor.getModel().getLinesContent();    //獲取每一行的內(nèi)容

monaco.editor.setTheme('vs-dark');      //設(shè)置主題

editor._configuration._rawOptions.language  //獲取編輯器當前語言(初始化值)
editor.getModel().getLanguageId()           //動態(tài)(已改變編輯器語言)

//改變屬性
editor.updateOptions({
  //關(guān)閉行號
  lineNumbers: "off"
});

//內(nèi)容改變事件
editor.onDidChangeModelContent(function(e){
  console.log(e);
  console.log(editor.getValue());
});

//添加按鍵監(jiān)聽
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function () {
  console.log('Ctrl + S 保存')
})

editor.trigger('a', 'editor.action.formatDocument') //觸發(fā):格式化文檔,更多支持項:editor._actions

//渲染代碼得到HTML
monaco.editor.colorize('console.log("Hello world!");', 'javascript').then(function (data) {
    console.log(data);
});

//渲染節(jié)點代碼
console.log("Hello world!");
monaco.editor.colorizeElement(document.getElementById('code'));


請登錄后查看

Always Prosperous Yang 最后編輯于2023-02-18 17:48:02

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認正序 回復(fù)倒序 點贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
3456
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準確時需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認打賞

微信登錄/注冊

切換手機號登錄

{{ bind_phone ? '綁定手機' : '手機登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服