Hi,
I am trying to use slots in a component to add optional filters in a component.
e.g. I have a form component which handles ajax requests. All form fields go inside the component and referenced with
But it looks like non of the data can be passed to the component from a slot, as apposed to a binding on the component element.
Component:
<template>
<form class="form" :action="action" :method="method" v-on:submit.prevent="ajaxSubmit">
<slot></slot>
</form>
</template>
<script>
module.exports = {
props: {
action: {
required: true,
type: String
},
method: {
default: 'post',
required: false,
type: String
}
},
data() {
return {
formData: {}
}
},
methods: {
ajaxSubmit() {
// Do ajax
}
},
}
</script>
Html:
<ajax-form action="#">
<input type="text" name="name" v-model="formData.name">
...
<button type="submit" class="btn btn-primary">Add Campaign</button>
</ajax-form>
Vue warn]: Property or method "formData" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
(found in root instance)
Any suggestions? Thanks