回答編集履歴

2

誤字修正

2019/12/01 14:33

投稿

nico25
nico25

スコア830

test CHANGED
@@ -12,20 +12,16 @@
12
12
 
13
13
 
14
14
 
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
15
  ### 1. 変更点
26
16
 
27
17
 
28
18
 
19
+ 以下 render プロパティを定義する方法を書きます。
20
+
21
+
22
+
23
+
24
+
29
25
  #### 1.1. JavaScript ファイル
30
26
 
31
27
 
@@ -64,7 +60,7 @@
64
60
 
65
61
  //
66
62
 
67
- import from "./hello_world.vue"
63
+ import test_comp from "./hello_world.vue"
68
64
 
69
65
 
70
66
 
@@ -78,130 +74,130 @@
78
74
 
79
75
  // },
80
76
 
77
+ render: h => h(test_comp)
78
+
79
+ });
80
+
81
+ ```
82
+
83
+
84
+
85
+ #### 1.2. HTML ファイル
86
+
87
+
88
+
89
+ ```
90
+
91
+ <!--
92
+
93
+ 変更前
94
+
95
+ -->
96
+
97
+ <html>
98
+
99
+ <head>
100
+
101
+ <meta charset="utf8">
102
+
103
+ </head>
104
+
105
+ <body>
106
+
107
+ <div id="app">
108
+
109
+ <mycomp></mycomp>
110
+
111
+ </div>
112
+
113
+ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
114
+
115
+ <script src="index.js"></script>
116
+
117
+ </body>
118
+
119
+ </html>
120
+
121
+ ```
122
+
123
+ ```
124
+
125
+ <!--
126
+
127
+ 変更後
128
+
129
+ -->
130
+
131
+ <html>
132
+
133
+ <head>
134
+
135
+ <meta charset="utf8">
136
+
137
+ </head>
138
+
139
+ <body>
140
+
141
+ <div id="app">
142
+
143
+ <!-- <mycomp></mycomp> -->
144
+
145
+ </div>
146
+
147
+ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
148
+
149
+ <script src="index.js"></script>
150
+
151
+ </body>
152
+
153
+ </html>
154
+
155
+ ```
156
+
157
+
158
+
159
+ ### 2. 補足
160
+
161
+
162
+
163
+ #### 2.1. エラーについて
164
+
165
+ components プロパティを使う書き方は、正しい様に自分も思えるのですが。もし上記の解決策で通るなら Webpack でコンパイルする場合は、template プロパティまたは render プロパティの指定が、必要になるのだと思われます。
166
+
167
+
168
+
169
+ > "コンポーネントのマウントに失敗しました: `template` または `render` 関数が未定義です。"
170
+
171
+ > "Failed to mount component: template or render function not defined"
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ #### 2.2. 優先順位
180
+
181
+ id=app で指定したものの配下は消されてしまうようです。なので id=app は子要素を持たない様に注意してください。
182
+
183
+
184
+
185
+ > The render function has priority over the render function compiled from template option or in-DOM HTML template of the mounting element which is specified by the el option.
186
+
187
+ > https://vuejs.org/v2/api/#render
188
+
189
+
190
+
191
+ #### 2.3. 描画関数
192
+
193
+ render 関数, 日本語訳で描画関数とよく書かれています。
194
+
195
+ ```javascript
196
+
197
+ // #app で指定されたタグが App タグになる。
198
+
81
199
  render: h => h(App)
82
200
 
83
- });
84
-
85
- ```
86
-
87
-
88
-
89
- #### 1.2. HTML ファイル
90
-
91
-
92
-
93
- ```
94
-
95
- <!--
96
-
97
- 変更前
98
-
99
- -->
100
-
101
- <html>
102
-
103
- <head>
104
-
105
- <meta charset="utf8">
106
-
107
- </head>
108
-
109
- <body>
110
-
111
- <div id="app">
112
-
113
- <mycomp></mycomp>
114
-
115
- </div>
116
-
117
- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
118
-
119
- <script src="index.js"></script>
120
-
121
- </body>
122
-
123
- </html>
124
-
125
- ```
126
-
127
- ```
128
-
129
- <!--
130
-
131
- 変更後
132
-
133
- -->
134
-
135
- <html>
136
-
137
- <head>
138
-
139
- <meta charset="utf8">
140
-
141
- </head>
142
-
143
- <body>
144
-
145
- <div id="app">
146
-
147
- <!-- <mycomp></mycomp> -->
148
-
149
- </div>
150
-
151
- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
152
-
153
- <script src="index.js"></script>
154
-
155
- </body>
156
-
157
- </html>
158
-
159
- ```
160
-
161
-
162
-
163
- ### 2. 補足
164
-
165
-
166
-
167
- #### 2.1. エラーについて
168
-
169
- components プロパティを使う書き方は、正しい様に自分も思えるのですが。もし上記の解決策で通るなら Webpack でコンパイルする場合は、template プロパティまたは render プロパティの指定が、必要になるのだと思われます。
170
-
171
-
172
-
173
- > "コンポーネントのマウントに失敗しました: `template` または `render` 関数が未定義です。"
174
-
175
- > "Failed to mount component: template or render function not defined"
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
- #### 2.2. 優先順位
184
-
185
- id=app で指定したものの配下は消されてしまうようです。なので id=app は子要素を持たない様に注意してください。
186
-
187
-
188
-
189
- > The render function has priority over the render function compiled from template option or in-DOM HTML template of the mounting element which is specified by the el option.
190
-
191
- > https://vuejs.org/v2/api/#render
192
-
193
-
194
-
195
- #### 2.3. 描画関数
196
-
197
- render 関数, 日本語訳で描画関数とよく書かれています。
198
-
199
- ```javascript
200
-
201
- // #app で指定されたタグが App タグになる。
202
-
203
- render: h => h(App)
204
-
205
201
  ```
206
202
 
207
203
 

1

誤字修正

2019/12/01 14:32

投稿

nico25
nico25

スコア830

test CHANGED
@@ -194,9 +194,33 @@
194
194
 
195
195
  #### 2.3. 描画関数
196
196
 
197
- render 関数, 日本語訳で描画関数とよく書かれています。SFC の template タグで囲んでいるものも
197
+ render 関数, 日本語訳で描画関数とよく書かれています。
198
+
198
-
199
+ ```javascript
200
+
201
+ // #app で指定されたタグが App タグになる。
202
+
203
+ render: h => h(App)
204
+
205
+ ```
206
+
207
+
208
+
209
+ ```javascript
210
+
211
+ // # app で指定された DOM が div タグになる
212
+
213
+ render: h => h(div)
214
+
215
+ ```
216
+
217
+
218
+
219
+
220
+
221
+ SFC の template タグで囲んでいるものも実際には関数で書くことができます。
222
+
199
- 実際には関数で書くことができます。細かいことをするときに必要になるそうです。
223
+ 細かいことをするときに必要になるそうです。
200
224
 
201
225
 
202
226