質問編集履歴

2

タイトル変更

2019/09/11 07:42

投稿

pmo23
pmo23

スコア14

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

1

コード追加

2019/09/11 07:42

投稿

pmo23
pmo23

スコア14

test CHANGED
File without changes
test CHANGED
@@ -409,3 +409,95 @@
409
409
  }
410
410
 
411
411
  ```
412
+
413
+
414
+
415
+ ###resources/js/store/auth.js
416
+
417
+ ```
418
+
419
+ const state = {
420
+
421
+ user: null
422
+
423
+ }
424
+
425
+
426
+
427
+ const getters = {
428
+
429
+ check: state => !! state.user,
430
+
431
+ username: state => state.user ? state.user.name : ''
432
+
433
+ }
434
+
435
+
436
+
437
+ const mutations = {
438
+
439
+ setUser (state, user) {
440
+
441
+ state.user = user
442
+
443
+ }
444
+
445
+ }
446
+
447
+
448
+
449
+ const actions = {
450
+
451
+ async register (context, data) {
452
+
453
+ const response = await axios.post('/api/register', data)
454
+
455
+ context.commit('setUser', response.data)
456
+
457
+ },
458
+
459
+ async login (context, data) {
460
+
461
+ const response = await axios.post('/api/login', data)
462
+
463
+ context.commit('setUser', response.data)
464
+
465
+ },
466
+
467
+ async logout (context) {
468
+
469
+ const response = await axios.post('/api/logout')
470
+
471
+ context.commit('setUser', null)
472
+
473
+ },
474
+
475
+ async currentUser (context) {
476
+
477
+ const response = await axios.get('/api/user')
478
+
479
+ const user = response.data || null
480
+
481
+ context.commit('setUser', user)
482
+
483
+ }
484
+
485
+ }
486
+
487
+
488
+
489
+ export default {
490
+
491
+ namespaced: true,
492
+
493
+ state,
494
+
495
+ getters,
496
+
497
+ mutations,
498
+
499
+ actions
500
+
501
+ }
502
+
503
+ ```