I want to implement the function of finding different strings and find a diff package, which has quite complete functions. The official example uses this:
const Diff = require('diff'); const diff = (one, other);
However, you cannot use require when using vue+vite.
Entering the diff package found a solution. (I am using 5.1.0, and I am not sure if I can use it like this in earlier versions)
Introduced in vue
import {Diff} from 'diff';
use:
var characterDiff = new Diff(); function diffChars(oldStr, newStr, options) { return (oldStr, newStr, options); } diffChars(oriText, resText,{}).forEach( function(part){ (part) if() { = "<span style='color:#2D93CA;font-size:16px;'>" + + "</span>" }} );
Other functions are similar. You need to find the code before and after new Diff() in the lib/file in the diff package, and rewrite it yourself in combination with the corresponding function code in /lib/diff.
This is the end of this article about vue+vite+ usage summary. For more related vue vite content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!