首页 > 其他分享 >vue3-code-diff

vue3-code-diff

时间:2022-10-27 15:55:23浏览次数:77  
标签:code false string boolean CodeDiff vue3 diff

vue3-code-diff

Vue2 / Vue3 可用的 code diff 插件 是 vue-code-diff

安装

# With NPM
npm i v-code-diff

# With Yarn
yarn add v-code-diff

全局注册

import {createApp} from 'vue'
import CodeDiff from 'v-code-diff'

app
  .use(CodeDiff)
  .mount('#app')

使用

<template>
  <code-diff
      :old-string="'12345'"
      :new-string="'3456'"
      file-name="test.txt"
      output-format="side-by-side"/>
</template>

局部使用

在 vue 文件中

<template>
  <code-diff
      :old-string="'12345'"
      :new-string="'3456'"
      file-name="test.txt"
      output-format="side-by-side"/>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
import {CodeDiff} from 'v-code-diff'

export default defineComponent({
  components: {
    CodeDiff
  }
})
</script>

事件

事件名称 说明 回调参数
before-render 渲染前触发 -
after-render 渲染后触发 -

参数

参数 说明 类型 可选值 默认值
highlight 控制是否高亮代码 boolean - true
language 代码语言,如typescript。不填会自动判断。 查看全部支持语言 string - -
old-string 陈旧的字符串 string - -
new-string 新的字符串 string - -
context 不同地方上下间隔多少行不隐藏 number - -
outputFormat 展示的方式 string line-by-line,side-by-side line-by-line
drawFileList 展示对比文件列表 boolean - false
renderNothingWhenEmpty 当无对比时不渲染 boolean - false
diffStyle 差异风格, 单词级差异或字母级差异 string word, char word
fileName 文件名 string - -
isShowNoChange 当无对比时展示源代码 boolean - false
trim 移除字符串前后空白字符 boolean - false
language 对比的文本语言 boolean - false
noDiffLineFeed 不 diff windows 换行符(CRLF)与 linux 换行符(LF) boolean - false

实例

main.ts

import CodeDiff from 'v-code-diff'
// use
const app = createApp(App)
app.use(VMdPreview)
app.use(CodeDiff)

vue

const oldContent = ref('123') //存旧内容
const newContent = ref('321') //存新内容
<code-diff
    :old-string="oldContent"
    :new-string="newContent"
    :file-name="rArticle.title"
    output-format="line-by-line"
    :draw-file-list="true"
    :context="1"
/>

image

标签:code,false,string,boolean,CodeDiff,vue3,diff
From: https://www.cnblogs.com/ouyangkai/p/16832544.html

相关文章

  • VS Code 配置JAVA环境
    1.首选添加如中文不好可先添加中文语言包,2.添加DebuggerforJava3.添加ExtensionPackForJava4。添加LanguageSupportfor Java至此,简单的学习环境已可以 ......
  • leetcode 234. 回文链表 js 实现
    给你一个单链表的头节点head,请你判断该链表是否为回文链表。如果是,返回true;否则,返回false。 示例1:输入:head=[1,2,2,1]输出:true示例2:输入:head=[1,2]输出......
  • vs code c++入门
    新建工程命令行创建vscode提供了命令行打开工作目录的功能mkdirplaygroundcdplaygroudcode.UI打开直接使用File->openFoldercommand模式使用F1快捷键可以打开......
  • leetcode-1758-easy
    MinimumChangesToMakeAlternatignBinaryStringYouaregivenastringsconsistingonlyofthecharacters'0'and'1'.Inoneoperation,youcanchangeany......
  • leetcode-704-easy
    BinarySearchGivenanarrayofintegersnumswhichissortedinascendingorder,andanintegertarget,writeafunctiontosearchtargetinnums.Iftargete......
  • 【JSON】Python读取JSON文件报错json.decoder.JSONDecodeError的问题
    报错json.decoder.JSONDecodeError:Expectingpropertynameenclosedindoublequotes:line*column*(char*)解决百度到了多种情况:编码使用UTF-8键值用双引......
  • leetcode 206. 反转链表 js实现
    给你单链表的头节点head,请你反转链表,并返回反转后的链表。 示例1:输入:head=[1,2,3,4,5]输出:[5,4,3,2,1]示例2:输入:head=[1,2]输出:[2,1]示例3:输入:head=[]输出......
  • code-server
    code-serverUsage#https://github.com/linuxserver/docker-code-server/blob/master/README.md#PORT:8443dockerpulllinuxserver/code-serverdockerrun--detac......
  • 【leetcode插件】使用
    快捷键如图中的文档注释中的类,没有快捷键可以一次性取消,如果一行一行删又太费事,我们可以用这个方法。光标放在这里,按下Alt+鼠标左键,就可以对多行进行删除,简单方便。......
  • Vscode自动生成文件注释和函数注释插件使用指南
    一、插件安装插件名:koroFileHeade插件安装二、插件配置打开配置文件添加配置//函数注释CTRL+ALT+T"fileheader.cursorMode":{"Fu......