I have a form created in vue and added to a blade page.
app.js
new Vue({
router,
components: {
'advice-form': AdviceForm,
}
}).$mount('#app');
blade.php
<div class="my-6">
<advice-form></advice-form>
</div>
AdviceForm Component
<template>
<input
class="md:w-auto w-full"
type="text"
name="name"
id="name"
placeholder="Full name"
v-model="name"
/>
</template>
<script>
export default {
name: "AdviceForm",
methods: {
data() {
return {
name: ''
};
}
}
};
</script>
When I try to add v-model for inputs I get an error saying Property or method "name" is not defined on the instance but referenced during render.
I am sure the name
is defined in the data property. Also, the <advice-form></advice-form>
is placed within the #app div in blade page.
Can anyone help me figure out what is the problem?
Change your script to the following and try not to use any reserved keywords.
new Vue({
router,
components: [AdviceForm],
}).$mount('#app');
<script>
export default {
name: "AdviceForm",
// data should be function outside the
// methods and try a non reserved keyword.
data: function() {
return {
form_name: ''
};
},
methods: {
// All the methods
},
components: []
};
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With