Skip to content

Commit 76b50bd

Browse files
MSCAUJustineo
authored andcommitted
Added usage information about inline-templates and x-templates (#1853)
* Added usage information about inline-templates and x-templates I wasted a whole day on this issue as it wasn't documented, AFAIK. StackOverflow people thankfully were able to help: https://stackoverflow.com/questions/52940350/vue-component-error-property-or-method-x-is-not-defined-on-the-instance-but-ref * Corrected inline-template sentence Found that the inline-template syntax requires the component template definition to reside within the DOM element to which Vue is attached.
1 parent 0c51ca0 commit 76b50bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/v2/guide/components-edge-cases.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,11 @@ components: {
331331
</my-component>
332332
```
333333

334-
<p class="tip">不过,<code>inline-template</code> 会让你模板的作用域变得更加难以理解。所以作为最佳实践,请在组件内优先选择 <code>template</code> 选项或 <code>.vue</code> 文件里的一个 <code>&lt;template&gt;</code> 元素来定义模板。</p>
334+
内联模板需要定义在 Vue 所属的 DOM 元素内。
335335

336-
### X-Templates
336+
<p class="tip">不过,<code>inline-template</code> 会让模板的作用域变得更加难以理解。所以作为最佳实践,请在组件内优先选择 <code>template</code> 选项或 <code>.vue</code> 文件里的一个 <code>&lt;template&gt;</code> 元素来定义模板。</p>
337+
338+
### X-Template
337339

338340
另一个定义模板的方式是在一个 `<script>` 元素中,并为其带上 `text/x-template` 的类型,然后通过一个 id 将模板引用过去。例如:
339341

@@ -349,6 +351,8 @@ Vue.component('hello-world', {
349351
})
350352
```
351353

354+
x-template 需要定义在 Vue 所属的 DOM 元素外。
355+
352356
<p class="tip">这些可以用于模板特别大的 demo 或极小型的应用,但是其它情况下请避免使用,因为这会将模板和该组件的其它定义分离开。</p>
353357

354358
## 控制更新

0 commit comments

Comments
 (0)