surmon-china / vue-codemirror

@codemirror code editor component for @vuejs
https://github.surmon.me/vue-codemirror
MIT License
3.28k stars 382 forks source link

动态改变editorOption #15

Closed GuessEver closed 7 years ago

GuessEver commented 7 years ago

比如我想动态改变语言mode

GuessEver commented 7 years ago

直接改editorOption变量的话,切换的时候代码会消失,而且语法高亮似乎也并没有改变

virusdefender commented 7 years ago

你可能需要自己去watch一下option,然后调用$refs.myEditor.editor.setOption()方法

surmon-china commented 7 years ago

@virusdefender 好办法!

yandwuhan commented 7 years ago

@virusdefender @surmon-china 我用了$refs.myEditor.editor.setOption()方法之后,打印选项来看mode的值被改变了,但是语法高亮和提示功能全部没了,就像mode为空一样,所有语言都不匹配了

virusdefender commented 7 years ago

@yandwuhan 麻烦贴下代码吧。

yandwuhan commented 7 years ago

我后来的解决办法是把你的那个又封装了一层,在外层传入codemirror配置参数,和挂载的id,然后每个文本框新建一个vue实例

在 2017-03-02 15:02:06,"李扬" notifications@github.com 写道:

@yandwuhan 麻烦贴下代码吧。

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

virusdefender commented 7 years ago

@yandwuhan 之前忘说了。。你可以看下我的用法

https://github.com/QingdaoU/OnlineJudgeFE/blob/master/src/components/CodeMirror.vue https://github.com/QingdaoU/OnlineJudgeFE/blob/master/src/views/problem/Problem.vue

surmon-china commented 7 years ago

v3.0.0 will fix it.