【发布时间】:2018-07-06 18:21:35
【问题描述】:
我试图了解<template> 的用例及其功能。引用了the docs,我仍然很困惑。
考虑 any.vue 文件中的以下代码:
<template>
<div class="top-right links">
<!-- Why use <template> here instead of a div, for example? -->
<template v-if="authenticated">
<router-link :to="{ name: 'home' }">
{{ $t('home') }}
</router-link>
</template>
<template v-else>
<router-link :to="{ name: 'login' }">
{{ $t('login') }}
</router-link>
</template>
</div>
</template>
我们为什么要使用<template> 而不是简单的<div>,使用<template> 与使用<custom-component> 有何不同?
【问题讨论】:
-
您链接到的文档与
<template>标签没有任何关系。 -
@JJJ 呜呜——谢谢!现在更正了:)!
标签: javascript vue.js vuejs2 templating