Full-Stack Web Development with Vue.js and Node

(singke) #1
Building the Real Application Chapter 5

},
...

All the methods that we will have will be added in this section. Now that we have our


placeholder for submit, let's modify this piece of code to incorporate the Movie Add form:


<script>
import axios from 'axios';

export default {
data: () => ({
valid: true,
name: '',
description: '',
genre: '',
release_year: '',
nameRules: [
v => !!v || 'Movie name is required',
],
select: null,
years: [
'2018',
'2017',
'2016',
'2015',
],
}),
methods: {
submit() {
if (this.$refs.form.validate()) {
return axios({
method: 'post',
data: {
name: this.name,
description: this.description,
release_year: this.release_year,
genre: this.genre,
},
url: 'http://localhost:8081/movies',
headers: {
'Content-Type': 'application/json',
},
})
.then(() => {
this.$router.push({ name: 'Home' });
this.$refs.form.reset();
})
Free download pdf