Skip to content

Commit

Permalink
call BE endpoint, make add category work
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 27, 2023
1 parent 9d0c9be commit bddb979
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<label>ImageURL</label>
<input type="url" class="form-control" v-model="imageURL" required>
</div>
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-primary" @click="addCategory">Submit</button>
</form>
</div>
<div class="col-3"></div>
Expand All @@ -31,6 +31,9 @@
</template>

<script>
var axios = require('axios')
import swal from 'sweetalert';
export default {
data(){
return {
Expand All @@ -39,9 +42,37 @@
imageURL : null,
}
},
props : [],
methods : {
async addCategory() {
const newCategory = {
categoryName : this.categoryName,
description : this.description,
imageUrl : this.imageURL,
};
//const baseURL = "https://limitless-lake-55070.herokuapp.com/";
const baseURL = "http://localhost:9999/";
await axios({
method: 'post',
url: baseURL+"category/create",
data : JSON.stringify(newCategory),
headers: {
'Content-Type': 'application/json'
}
})
.then(() => {
swal({
text: "Category Added Successfully!",
icon: "success",
closeOnClickOutside: false,
});
})
.catch(err => console.log(err));
}
},
mounted(){
}
}
</script>
Expand Down

0 comments on commit bddb979

Please sign in to comment.