解决 codemirror5 报错 Cannot read properties of undefined (reading 'map')

479 阅读1分钟

一、报错

在 Vue3 里使用 codemirror5 时,报错 Cannot read properties of undefined (reading 'map'),具体如图:

image.png

二、解决方法

CodeMirror 的实例对象不能使用双向数据绑定,否则就会报这个错,可以单独写一个变量。 示例代码如下:

<script setup>
let editor = null // 这是对的
// let editor = ref(null) 这种是双向绑定,会报错

editor = CodeMirror.fromTextArea(textareaRef.value, {
    mode: 'application/json'
})
</script>

三、参考链接

github issue