質問編集履歴

1

injectのテスト

2019/10/03 09:11

投稿

ss-nantoka
ss-nantoka

スコア18

test CHANGED
File without changes
test CHANGED
@@ -86,4 +86,72 @@
86
86
 
87
87
 
88
88
 
89
+ ****************
90
+
91
+ ご回答いただき、下記のようにすることで、storeから利用できるようになりましたが、gettersの中では、this参照できないです。何か別に設定など必要であるかご存知でしょうか?
92
+
93
+
94
+
95
+ /plugin/test.js
96
+
97
+ ```
98
+
99
+ const test = aaa => {
100
+
101
+ console.log(aaa)
102
+
103
+ }
104
+
105
+
106
+
107
+ export default ({ app }, inject) => {
108
+
109
+ inject('test', test)
110
+
111
+ }
112
+
113
+ ```
114
+
115
+
116
+
117
+ storeファイル
118
+
119
+ - gettersではエラー
120
+
121
+ ```
122
+
123
+ export const getters = {
124
+
125
+ getTest: state => {
126
+
127
+ this.$test('テストプラグイン')
128
+
129
+ }
130
+
131
+ }
132
+
133
+ ```
134
+
135
+
136
+
137
+ - actionsでは、OK
138
+
139
+ ```
140
+
141
+ export const actions = {
142
+
143
+ actionsTest({ commit, state }) {
144
+
145
+ this.$test('テストプラグイン')
146
+
147
+ }
148
+
149
+ }
150
+
151
+ ```
152
+
153
+
154
+
155
+
156
+
89
157
  よろしくお願いいたします。