一、安装 string-similarity库 npm install string-similarity 二、html <div> <input type="text" v-model="string1" placeholder="文本1" /> </div> <div> <input type="text" v-model="string2" placeholder="文本2" /> </div> <div> <button @click="compare">比较</button> </div> 三、js import stringSimilarity from "string-similarity"; export default { data() { return { string1: "", string2: "" }; }, methods: { compare() { // 使用string-similarity库计算语义相似度 const similarity = stringSimilarity.compareTwoStrings( this.sentence1, this.sentence2 ); console.log(similarity) }, }, }; 四、结果展示