Skip to content

Commit

Permalink
add EditCategory view
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 27, 2023
1 parent 17ef9a9 commit f1706af
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template>
<div class="container">
<div class="row">
<div class="col-12 text-center">
<h3 class="pt-3">Edit Category</h3>
</div>
</div>

<div class="row">
<div class="col-3"></div>
<div class="col-md-6 px-5 px-md-0">
<form>
<div class="form-group">
<label>Category Name</label>
<input type="text" class="form-control" v-model="categoryName" required>
</div>
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control" v-model="description" required>
</div>
<div class="form-group">
<label>ImageURL</label>
<input type="url" class="form-control" v-model="imageUrl" required>
</div>
<button type="button" class="btn btn-primary" @click="editCategory">Submit</button>
</form>
</div>
<div class="col-3"></div>
</div>
</div>
</template>

<script>
var axios = require('axios')
import swal from 'sweetalert';
export default {
data(){
return {
id : null,
categoryName : null,
description : null,
imageUrl : null,
categoryIndex : null
}
},
props : ["baseURL", "category"],
methods : {
async editCategory() {
const updatedCategory = {
id : this.id,
categoryName : this.categoryName,
description : this.description,
imageUrl : this.imageUrl,
}
await axios({
method: 'post',
url: this.baseURL+"category/update/"+this.id,
data : JSON.stringify(updatedCategory),
headers: {
'Content-Type': 'application/json'
}
})
.then(() => {
swal({
text: "Category Updated Successfully!",
icon: "success",
closeOnClickOutside: false,
});
})
.catch(err => console.log(err));
}
},
mounted() {
this.id = this.$route.params.id;
this.categoryName = this.category.categoryName;
this.description = this.category.description;
this.imageUrl = this.category.imageUrl;
}
}
</script>

<style scoped>
h4 {
font-family: 'Roboto', sans-serif;
color: #484848;
font-weight: 700;
}
</style>

0 comments on commit f1706af

Please sign in to comment.