I'm new in VueJS and I am trying to create a custom form component.
I am using http://element.eleme.io elements. So I created a new Form.vue file
<template>
<el-form :model="data">
<slot></slot>
</el-form>
</template>
<script>
import { FormItem, Input } from 'element-ui';
export default {
name: 'general-form',
components: {
FormItem,
Input
},
props: ['data'],
mounted: function() {
console.log(this.data);
}
}
</script>
Here is my app.js
// Element.io
import { Form, FormItem, Input } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// Custom
import GeneralForm from '../../components/presentational-subsystem/form/Form.vue';
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);
Vue.config.devtools = true;
var contactsPage = new Vue({
el: '#contacts-page',
components: {
GeneralForm
}
});
And here is my view:
<div id="contacts-page">
<general-form id="contacts-form" :data="{subject: 'abc'}" action="/contacts" method="post">
<el-form-item label="Subject" prop="subject">
<el-input v-model="data.subject"></el-input>
</el-form-item>
</general-form>
</div>
But I get this error in the console:
[Vue warn]: Property or method "formData" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
I know that if I change Vue object to this:
var contactsPage = new Vue({
el: '#contacts-page',
data: { formData: {} }
components: {
GeneralForm
}
});
the error disappears, but then form is not reactive any more. I tried to follow this example:
http://element.eleme.io/#/en-US/component/form
and my markup is actually the same, but when I use Vue dev tools, I can see that my formData variable inside my Form.vue component is different from the shared formData variable in my Vue instance.
My question would be how can I make <el>
elements use formData from my Form component that I created?