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

質問編集履歴

1

injectのテスト

2019/10/03 09:11

投稿

ss-nantoka
ss-nantoka

スコア18

title CHANGED
File without changes
body CHANGED
@@ -42,4 +42,38 @@
42
42
  - 「utilFunctions.test1」といった指定ができないです
43
43
 
44
44
 
45
+ ****************
46
+ ご回答いただき、下記のようにすることで、storeから利用できるようになりましたが、gettersの中では、this参照できないです。何か別に設定など必要であるかご存知でしょうか?
47
+
48
+ /plugin/test.js
49
+ ```
50
+ const test = aaa => {
51
+ console.log(aaa)
52
+ }
53
+
54
+ export default ({ app }, inject) => {
55
+ inject('test', test)
56
+ }
57
+ ```
58
+
59
+ storeファイル
60
+ - gettersではエラー
61
+ ```
62
+ export const getters = {
63
+ getTest: state => {
64
+ this.$test('テストプラグイン')
65
+ }
66
+ }
67
+ ```
68
+
69
+ - actionsでは、OK
70
+ ```
71
+ export const actions = {
72
+ actionsTest({ commit, state }) {
73
+ this.$test('テストプラグイン')
74
+ }
75
+ }
76
+ ```
77
+
78
+
45
79
  よろしくお願いいたします。