回答问题前请先看我的版本我的代码,这一点非常关键
请给你出代码的截图 这是第二点,直接粘贴AI来的代码 我直接无视,三周了 我尝试过各种Ai
请不要粘贴AI 过来的代码,谢谢! 全是不可用的玩意
放置了两个Codemirror,做JSON数据对比,但是大部分资料都是混乱的,5.0 和 6.0 的使用完全不一致,尝试了降低版本,以及各种各博主的方法,但都是碎片
有没有什么方式方法在上面的版本里可以让指定行的指定字符设置class或者style 修改背景颜色的方式方法?
document方法就算了,目前就是想把对比出来的数据不一致的行进行标注
vue-codemirror版本6.1.1
codemirror版本6.0.1
codemirror/view 版本6.21.2
codemirror/state 版本 6.2.1
vue版本 3.3.4
<template>
<Codemirror class="codeviewleft" v-model="codeviewleft" :linters="linter" :heightChanged="true" placeholder="Code goes here..." :style="{ height: '96vh' }" :indent-with-tab="true" :tab-size="2" :extensions="extensions" :styleActiveLine="true" @ready="handleReady" @blur="getValue" />
<Codemirror class="codeviewright" v-model="codeviewright" :linters="linter" :heightChanged="true" placeholder="Code goes here..." :style="{ height: '96vh' }" :indent-with-tab="true" :tab-size="2" :extensions="extensions" :styleActiveLine="true" @blur="getValue" />
<template>
<script setup>
import { ref,reactive,computed,shallowRef,onMounted } from 'vue'
import { Codemirror } from 'vue-codemirror'
import { json,jsonParseLinter } from '@codemirror/lang-json'
import { oneDark } from '@codemirror/theme-one-dark'
import { compare } from 'fast-json-patch'
import { countColumn } from '@codemirror/text';
import{EditorState}from"@codemirror/state"
import { Decoration, EditorView, highlightActiveLine } from "@codemirror/view";
const extensions = computed(() => [json(),oneDark])
const codeviewleft =ref('');
const codeviewright =ref('');
const handleReady = (payload) => {
console.log('↓')
console.log(payload)
view.value = payload.view
state.value = payload.state
}
const getCodemirrorStates = () => {
console.log(view.value)
const state = view.value.state
const ranges = state.selection.ranges
const selected = ranges.reduce((r, range) => r + range.to - range.from, 0)
const cursor = ranges[0].anchor
const length = state.doc.length
const lines = state.doc.lines
console.log(state)
console.log(selected)
console.log(cursor)
console.log(length)
console.log(lines)
}
</script>
<style lang='less' scoped>
.highlighted {
background-color: #ff0000;
}
</style
已安装包如下
"@codemirror/lang-json": "^6.0.1",
"@codemirror/state": "^6.2.1",
"@codemirror/text": "^0.19.6",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.20.2"
"fast-json-patch": "^3.1.1",
"vue-codemirror": "^6.1.1",
"codemirror": "^6.0.1"