πŸ““ TIL

[220526] vue payload

k_m_jin 2022. 5. 27. 01:55

- vue

member 은 λ³€μˆ˜μ™€ λ©”μ†Œλ“œλ₯Ό ν¬ν•¨ν•œ κ°œλ…

 

- payload.amount 

payload의 λ°μ΄ν„°νƒ€μž…μ€? 객체!

λ‚΄μž₯λ©”μ†Œλ“œκ°€ μ•„λ‹Œ 이상 μ ν‘œκΈ°λ²•μœΌλ‘œ λ‚˜νƒ€λ‚Έ 객체!

 

- createApp

 

- todo API

import {createStore} from 'vuex'
import axios from 'axios'

const END_POINT = 'https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos'
const headers = {
  //νŠΉμˆ˜κΈ°ν˜Έκ°€ μžˆλŠ” 속성은 λ”°μ˜΄ν‘œλ₯Ό λ„£λŠ”λ‹€
  "content-type": "application/json",
  apikey: "FcKdtJs202204",
  username: "KDT2_KimMyeongJin"
}


export default createStore ({

state(){
  return{
    todos: []
  }
},
mutations: {
  setTodos(state,payload){
    state.todos = payload
  }
},
actions: {
  async readTodos({commit}){
    const res = await axios({
      url: END_POINT,
      method: 'GET',
      headers
    })
    console.log(res)
    commit('setTodos',res.data)
  },
  async createTodo(context, title){
    const res = await axios({
      url: 'https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos',
      method: 'POST',
      headers: {
        //νŠΉμˆ˜κΈ°ν˜Έκ°€ μžˆλŠ” 속성은 λ”°μ˜΄ν‘œλ₯Ό λ„£λŠ”λ‹€
        "content-type": "application/json",
        apikey: "FcKdtJs202204",
        username: "KDT2_KimMyeongJin"
      },
      data: {
        title
      }
    })
    // console.log(res)
  }
}
})
λ°˜μ‘ν˜•