teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

タイトル変更

2019/09/11 07:42

投稿

pmo23
pmo23

スコア14

title CHANGED
@@ -1,1 +1,1 @@
1
- postが上手くいきません2(Vue.js + Vue Router + Vuex とサーバーサイドに Laravel 使用しシングルペジ Web アプリケーションの開)
1
+ Laravel+vueでpost行なっ場合に422エラ生する
body CHANGED
File without changes

1

コード追加

2019/09/11 07:42

投稿

pmo23
pmo23

スコア14

title CHANGED
File without changes
body CHANGED
@@ -203,4 +203,50 @@
203
203
  ];
204
204
  }
205
205
  }
206
+ ```
207
+
208
+ ###resources/js/store/auth.js
209
+ ```
210
+ const state = {
211
+ user: null
212
+ }
213
+
214
+ const getters = {
215
+ check: state => !! state.user,
216
+ username: state => state.user ? state.user.name : ''
217
+ }
218
+
219
+ const mutations = {
220
+ setUser (state, user) {
221
+ state.user = user
222
+ }
223
+ }
224
+
225
+ const actions = {
226
+ async register (context, data) {
227
+ const response = await axios.post('/api/register', data)
228
+ context.commit('setUser', response.data)
229
+ },
230
+ async login (context, data) {
231
+ const response = await axios.post('/api/login', data)
232
+ context.commit('setUser', response.data)
233
+ },
234
+ async logout (context) {
235
+ const response = await axios.post('/api/logout')
236
+ context.commit('setUser', null)
237
+ },
238
+ async currentUser (context) {
239
+ const response = await axios.get('/api/user')
240
+ const user = response.data || null
241
+ context.commit('setUser', user)
242
+ }
243
+ }
244
+
245
+ export default {
246
+ namespaced: true,
247
+ state,
248
+ getters,
249
+ mutations,
250
+ actions
251
+ }
206
252
  ```