Guest User

Untitled

a guest
Aug 9th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <template>
  2. <div id="app">
  3. <AppHeader></AppHeader>
  4. <b-container>
  5. <b-row class="justify-content-center">
  6. <AddProduct @addProduct="addProduct"></AddProduct>
  7. <ListProduct :products="productList"></ListProduct>
  8. </b-row>
  9. </b-container>
  10. </div>
  11. </template>
  12.  
  13. <script>
  14. import AppHeader from './components/AppHeader.vue'
  15. import AddProduct from './components/AddProduct.vue'
  16. import ListProduct from './components/ListProduct.vue'
  17. import axios from 'axios'
  18.  
  19.  
  20. export default {
  21. name: 'App',
  22. components : {
  23. AppHeader,
  24. AddProduct,
  25. ListProduct,
  26. },
  27. data() {
  28. return {
  29. productList:[]
  30. }
  31. },
  32. methods: {
  33. async getProductList() {
  34. try {
  35. let result = await axios.get('http://localhost:3000/products')
  36. console.log(result.data)
  37. this.productList = result.data
  38. } catch (error) {
  39. console.log('Error', error)
  40. }
  41.  
  42. },
  43. async addProduct(newProduct) {
  44. console.log('newProduct', newProduct)
  45. }
  46. },
  47. mounted() {
  48. this.getProductList()
  49. }
  50. }
  51. </script>
  52.  
  53. <style>
  54. #app {
  55.  
  56. }
  57.  
  58. .error-message{
  59. color: red;
  60. }
  61. </style>
  62.  
Add Comment
Please, Sign In to add comment