I want to use the getProjects() method of Component 2 to refresh my table after adding a data. Both of these components are attached in a blade.php
Component 1.vue
methods: {
addData() {
this.attemptSubmit = true;
this.validate = true;
this.errors = [];
if (this.errors) event.preventDefault();
axios
.post('/api/department', {
department: this.department,
section: this.section
})
.then(response => {
this.validate = false;
this.department = '';
this.section = '';
this.errors = '';
this.output = response.data;
//--- I want to insert the getProjects() method here
})
.catch(error => this.errors = error.response.data.errors)
},
Component 2.vue
methods: {
getProjects(url = '/api/departments') {
this.tableData.draw++;
axios
.get(url, {params: this.tableData})
.then(response => {
let data = response.data;
if (this.tableData.draw == data.draw) {
this.projects = data.data.data;
this.configPagination(data.data);
}
})
.catch(errors => {
console.log(errors);
});
},