Advertisement
asimryu

addItemForm.vue

Apr 28th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <template>
  2. <div class="addItem">
  3. <input type="text" v-model="item.name" />
  4. <font-awesome-icon
  5. icon="plus-square"
  6. @click="addItem()"
  7. :class="[ item.name ? 'active' : 'inactive', 'plus']"
  8. />
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. data: function () {
  14. return {
  15. item: {
  16. name: ""
  17. }
  18. }
  19. },
  20. methods: {
  21. addItem() {
  22. if( this.item.name == '' ) return;
  23.  
  24. axios.post('api/item/store', {
  25. item: this.item
  26. })
  27. .then( response => {
  28. if( response.status == 201 ) {
  29. this.item.name = "";
  30. this.$emit('reloadlist');
  31. }
  32. })
  33. .catch(error => {
  34. console.log(error);
  35. })
  36. }
  37. }
  38. }
  39. </script>
  40. <style scoped>
  41. .addItem {
  42. display: flex;
  43. justify-content: center;
  44. align-items: center;
  45. }
  46. input {
  47. background: #f7f7f7;
  48. border: 0px;
  49. outline: none;
  50. padding: 5px;
  51. margin-right: 10px;
  52. }
  53. .plus {
  54. font-size: 20px;
  55. }
  56. .active {
  57. color: #00ce25;
  58. }
  59. .inactive {
  60. color: #999999;
  61. }
  62. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement