π 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)
}
}
})
λ°μν