vue:diff库实现文本对比

news/2024/7/9 23:57:03 标签: html, vue
htmledit_views">

官方文档 https://www.npmjs.com/package/diff

安装:npm install diff

内容

html"> <template>
    <div>
      <div style="white-space: pre-line;display: flex;">
        <div>
            <span class="default">{{oldStr}}</span>
        </div>
        <div>
         <span v-for="(item,index) in resultStr" :key="index" :class="item.added?'add':item.removed?'remove':'default'">{{item.value}}</span>
        </div>
      </div>
    </div>
  </template>
<script>
import {diffChars} from 'diff'
export default {
  name: 'CodeMirror',
  data() {
    return {
      resultStr: '',
      chineseStr: `让顾明渊和阮念心这对渣男贱女血债血偿!`,
      oldStr: `should try our best to help others when they are in need of help,but we should also protect ourselves from getting into trouble.If everyone tries a little kindness,our world will be full of love.`,
      newStr: `our best to help others when they are in need of help,but we also should also protect ourselves from getting into trouble.If everyone tries a little kindness,our world will be full of love.`
    };
  },
  mounted() {
    const d = diffChars(this.oldStr, this.newStr)
    this.resultStr = d
  }
};
</script>
<style scoped>
  .remove {
    color: red;
    background-color: #fee8e9;
    text-decoration: line-through;
  }
  .add {
    color: green;
    background-color: #ddffdd;
  }
  .default {
    color: grey;
  }
</style>

实例结果:


http://www.niftyadmin.cn/n/5087539.html

相关文章

第六章:路由交换机及操作系统

路由交换机及操作系统 一、路由器与交换机的作用与特点1.路由器1.1 作用1.2 特点 2.交换机2.1 作用2.2 特点 二、H3C路由器与交换机介绍1. 路由器2. 交换机 三、 H3C网络设备操作系统Comware1. 介绍2. 特点![在这里插入图片描述](https://img-blog.csdnimg.cn/2b24103028654878…

从零开始学习调用百度地图网页API:二、初始化地图,鼠标交互创建信息窗口

目录 代码结构headbodyscript 调试 代码 <!DOCTYPE html> <html> <head><meta http-equiv"Content-Type" content"text/html; charsetutf-8" /><meta name"viewport" content"initial-scale1.0, user-scalable…

private key ssh连接服务器

这里用到的软件是PuTTY。 https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 保存本地rsa文件后&#xff0c;打开软件PuTTYgen&#xff0c;点击Load导入文件&#xff0c;输入Key passphrase即密码&#xff0c;保存至本地。 随后在PuTTY配置ssh的用户名 来Cred…

ffmpeg跨平台arm编译-ubuntu

目录 1. 安装必要的编译器2. 安装必要的依赖项3. 配置编译选项4. 编译安装 1. 安装必要的编译器 32位系统&#xff1a; sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabihf sudo apt-get install g-arm-linux-gnueabihf64位系统&#xff1a; sudo apt-get u…

记录“在Unity动画播放协程内等待动画播放完成时回调”遇到的坑

情景是在动画播放完成时触发事件。 刚开始采用给动画绑定AnimationEvent来实现功能&#xff0c;后来出了问题&#xff1a;部分动画需要倒播&#xff0c;导致播放完成事件在播放开始时触发。 然后在动画播放协程内监测动画播放时间 Animator.GetCurrentAnimatorStateInfo(0).no…

Kafka SASL认证授权(五)ACL源码解析

Kafka SASL认证授权(五)ACL源码解析。 官网地址:https://kafka.apache.org/ 一、ACL检查流程解析 一起看一下kafka server的启动与监听流程: Kafka -> KafkaServer -> SocketServer、KafkaRequestHandler 其中KafkaServer做相关的初始化,包括SocketServer 与 han…

机器视觉在自动驾驶汽车中的应用与挑战

机器视觉在自动驾驶汽车中扮演着至关重要的角色&#xff0c;它使车辆能够感知和理解周围环境&#xff0c;以便自主驾驶。以下是机器视觉在自动驾驶汽车中的应用以及相关挑战&#xff1a; 应用&#xff1a; 障碍物检测与避让&#xff1a; 机器视觉系统可以检测和识别路上的障碍…