日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mocano editor中使用代码比对功能

發布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mocano editor中使用代码比对功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mocano editor中使用代碼比對功能

環境:vue2.x + typescript

使用前提請先看:vue2.x中monaco-editor的基礎使用

效果圖:

創建代碼公共組件

codeDiff.vue

<template><div class="editor" :id="id"></div> </template><script lang="ts"> import CodeDiff from "./codeDiff"; export default CodeDiff; </script><style lang="less" scoped> .editor {width: 100%;height: 635px;text-align: left; } </style>

codeDiff.ts

import { Vue, Component, Prop, Watch } from "vue-property-decorator"; import * as Monaco from "monaco-editor";interface ICode {value: string;language: string; }@Component export default class CodeDiff extends Vue {diffInstance: any;id = "";@Prop({ default: { value: "", language: "" } })oldCode!: ICode;@Prop({ default: { value: "", language: "" } })code!: ICode;created(): void {this.id = `editor${Math.random()}`;}@Watch("oldCode", { deep: true })oldWatch(): void {this.change();}@Watch("code", { deep: true })nowWatch(): void {this.change();}mounted(): void {this.init();}setModel(instance: any): void {// 此處可以把`original`和`modified`按情況創建模型,比如初始兩個都渲染,`original` 改變只創建`original`的model,`modified`改變只創建`modified`的modelinstance.setModel({original: Monaco.editor.createModel(this.oldCode.value,this.oldCode.language,),modified: Monaco.editor.createModel(this.code.value,this.code.language,),})}init(): void {const code: HTMLElement = document.getElementById(this.id) as HTMLElement;this.diffInstance = Monaco.editor.createDiffEditor(code, {wordWrap: "on",scrollBeyondLastLine: false,automaticLayout: true,readOnly: true,});this.setModel(this.diffInstance);}change(): void {if (this.diffInstance === null) {this.init();return;}this.setModel(this.diffInstance);} }

使用組件

<code-diff :old-code="oldCodeInfo" :code="codeInfo" />

總結

以上是生活随笔為你收集整理的mocano editor中使用代码比对功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。