美文网首页
前端代码差异化检测

前端代码差异化检测

作者: 不知名的狐妖 | 来源:发表于2021-12-10 08:41 被阅读0次

最近开发需求中要用到code差异化:

当场翻车

开始今天主角  [v-code-diff](https://github.com/Shimada666/v-code-diff/blob/master/README-zh.md)和`vue-code-diff`两者都是代码差异化的组件。今天之说`v-code-diff`.不要问什么,没有为什么,就是简单而已。Vue2 / Vue3 都支持的 code diff 插件

### 1、如何使用?

```bash

// 安装 v-code-diff

# With NPM

$ npm i v-code-diff

# With Yarn

$ yarn add v-code-diff

# Vue2 用户需要额外安装 composition-api

$ yarn add @vue/composition-api

```

### 2、使用

* 2.1、Vue2使用

  `全局注册`

 

  ```js

  // app.js

  import Vue from 'vue';

  import CodeDiff from 'v-code-diff'

 

  Vue.use(CodeDiff);

 

  ```

 

  ```vue

  // 文件中使用

  // *.vue

  <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>

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

 

  export default {

    name: 'App',

    components: {

      CodeDiff

    }

  }

  </script>

  ```

 

* 2.2、Vue3使用

  `全局注册`

  ```js

  // main.js

  import {createApp} from 'vue'

  import CodeDiff from 'v-code-diff'

  import App from 'App'

 

  const app=createApp(App)

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

  ```

  ```vue

  // 文件中使用

  // *.vue

  <template>

    <code-diff

        :old-string="'12345'"

        :new-string="'3456'"

        file-name="test.txt"

        output-format="side-by-side"/>

  </template>

  ```

 

  `局部注册`

  ```vue

  // 文件中使用

  // *.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`。不填会自动判断。 [查看全部支持语言](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md) | 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        |

 

* 结束

  最后欢迎订阅,文章若有不足欢迎指出。

```

```

相关文章

  • 前端代码差异化检测

    最近开发需求中要用到code差异化: 当场翻车 开始今天主角 [v-code-diff](https://gith...

  • grunt gulp

    grunt gulp grunt: 压缩代码,合并代码,检测代码书写规范... 前端自动化工具 构建项目 官网:h...

  • grunt

    grunt:基于:node 开发压缩代码,合并代码,检测代码书写规范...前端自动化工具构建项目官网:http...

  • grunt及gulp的使用

    grunt是压缩代码,合并代码,检测代码书写规范grunt也是前端自动化,构建项目工具grunt官网:http:/...

  • 关于文件上传漏洞的心得

    1. 最简单就是前端防护,后端不防护,即js检测绕过攻击,此时可以利用浏览器插件删除前端js检测代码或者可以通过b...

  • 文件上传

    1、客户端检测绕过(javascript 检测) 首先观察到提示只允许上传图片文件,那么前端的查看代码,当页...

  • cmft-前后端框架

    前端 Vue前端脚手架 Vue脚手架单入口/双入口 Vue工程的目录结构 Eslint:代码检测工具 Docker...

  • 项目中如何提高各单位配合效率,草稿

    接口联调的目的 1、为了前端能够集成数据能力,旨在在代码层面联调融合 2、闭环测试,a、检测接口本身能力 b、检测...

  • 搜索框模糊查询

    前端html代码 前端js代码 前端css代码 后端php返回json

  • ESLint

    检测语法和代码规范的前端工具 在 CLI 中使用 本地安装 ESLint 在项目根目录中创建配置文件 .eslin...

网友评论

      本文标题:前端代码差异化检测

      本文链接:https://www.haomeiwen.com/subject/unoffrtx.html