A source code field for vue-form-generator
<template>
<vue-form-generator :schema="schema" :model="model"></vue-form-generator>
</template>
<script>
export default {
data() {
return {
model: {
source: `<template></template>`
},
schema: {
fields: [{
type: "sourcecode",
label: "source code",
model: "source",
theme: 'eclipse',
mode: {
name: "javascript",
json: true
}
}]
}
};
}
};
</script>
npm install vfg-field-sourcecode
vfg-field-sourcecode can be used as a module in both CommonJS and ES modular environments.
When in non-modular environment, vfg-field-sourcecode will register all the components to vue by itself.
//
// You can register a component manually
//
import { FieldSourcecode } from 'vfg-field-sourcecode';
export default {
...
components: {
'field-sourcecode': FieldSourcecode
},
...
};
//
// or register the whole module with vue
//
import ModuleLibrary from 'vfg-field-sourcecode';
// Install this library
Vue.use(ModuleLibrary);
//
// You can register a component manually
//
var Vue = require('vue');
var ModuleLibrary = require('vfg-field-sourcecode');
var YourComponent = Vue.extend({
...
components: {
'field-sourcecode': ModuleLibrary.FieldSourcecode
},
...
});
//
// or register the whole module with vue
//
var Vue = require('vue');
var ModuleLibrary = require('vfg-field-sourcecode');
// Install this library
Vue.use(ModuleLibrary);
<script src="path/to/vue/vue.min.js"></script>
<script src="path/to/vfg-field-sourcecode/dist/vfg-field-sourcecode.min.js"></script>
<!-- Components are registered globally -->
schema: {
fields: [
{
type: "sourcecode",
label: "source code",
model: "source",
theme: 'monokai',
mode: "ruby"
}
]
}
Any supported CodeMirror option can be passed in the schema
. Available options are shown here.
When setting the mode
option in the schema, vfg-field-sourcecode
will automatically load the JS for the specified mode. This currently only works if you set the mode by name, not by mime type. Mode can either by set as as string, eg: mode: python
, or as an object, which is required if that mode supports options you want to set - eg: mode: { name: 'javascript', json: true }
. See here for more details.
See the GitHub release history.
See CONTRIBUTING.md.