surmon-china / vue-codemirror

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

vue1.0版本中使用codemirror,它的@changed方法不被触发 #6

Closed haoxutong closed 7 years ago

haoxutong commented 7 years ago

<codemirror :code="code" :options="editorOption" @changed="codeChange"> methods:{

        codeChange(newCode){
            console.log('newCode',newCode);
            this._changeSQL(this.uid,newCode)
        },

} 遇到两个问题,一个是codeChange方法不被触发,当我修改代码的时候,还有就是引入

这两个文件的配置项没有起作用, 我是直接在data中加配置项的 data(){ return { //codemirror的配置项 editorOption:{ lineNumbers: true,//设置行号 boolean mode: 'text/x-mysql',//当前code模式 模式的选择可以在CodeMirror.modes中查看 //此处是引用sql-hint.js的配置项 hintOptions:{ completeSingle: false, //当匹配只有一项的时候是否自动补全 tables: { table1: ['name', 'score', 'birthDate'], table2: ['name', 'population', 'size'] } },//表元信息 extraKeys: {//快捷键 可提供三种模式 sublime、emacs、vim。 使用时需要引入js支持包 "F9": function (editor) { format(editor); }, "F8": function (editor) { query(editor); } } } } }
surmon-china commented 7 years ago

@changed方法是给2.0用的

1.0你可以通过下面这些方式应用

<!-- 单向数据绑定(即codemirror的变化不会再响应回来) -->
<codemirror :code="code" :options="editorOption"></codemirror>
<!-- 双向数据绑定(2.0已废弃) -->
<codemirror :code.sync="code" :options="editorOption"></codemirror>

如果你要监听codemirror 的变化,可以双向数据绑定,并且在watch中watch你所绑定的变量,然后作出相应操作

haoxutong commented 7 years ago

哦 那请问你这插件可以加入 "hint/show-hint.js" "hint/sql-hint.js"这个两个js文件的配置项 实现autocomplete吗 我试着在editOption中加了 没有起作用 editorOption:{ lineNumbers: true,//设置行号 boolean value: 'SELECT * FROM table',//编辑框初始值 string mode: 'text/x-mysql',//当前code模式 模式的选择可以在CodeMirror.modes中查看 height: 100,//高度 indentUnit: 4,//缩进块用多少个空格表示 默认是2 autofocus: true, //此处是引用sql-hint.js的配置项 hintOptions:{ completeSingle: false, //当匹配只有一项的时候是否自动补全 tables: { table1: ['name', 'score', 'birthDate'], table2: ['name', 'population', 'size'] } },//表元信息 extraKeys: {//快捷键 可提供三种模式 sublime、emacs、vim。 使用时需要引入js支持包 "F9": function (editor) { format(editor); }, "F8": function (editor) { query(editor); } } }

surmon-china commented 7 years ago

如果有 hint/show-hint.js 来源的详细信息,可以提供一下

surmon-china commented 7 years ago

找到了,下一个版本增加/修复此功能,本周内完成

haoxutong commented 7 years ago

哇塞 果然是大神 坐等下一个版本 给你点32个赞

haoxutong commented 7 years ago

还有一个比较大的问题 现在code数据不是放在data中 是放在computed中计算属性得到的,这样我改变其值,如何检测其变化,将计算属性的来源值改变 computed:{code() getTabData.sql} 我要在改变codemirror中的值时候去改变 getTabData.sql的值,应该如何去做?

surmon-china commented 7 years ago

文档通读一遍,这个问题就解决了

haoxutong commented 7 years ago

你是指vue的文档还是你的组件文档 找了一遍没找着 球指教

surmon-china commented 7 years ago

https://github.com/surmon-china/vue-codemirror#use-in-components

已支持