我将为您翻译IT技术相关内容。请参考以下代码,其中包含了
在any.vue文件中,考虑以下代码:
为什么我们要使用
<template>
和它的功能,通过查阅文档,我还是有些困惑。在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 v-if="authenticated">
,而不是使用<div v-if="authenticated">
的原因所在... - Michałtemplate
而不是div
,因为它不会出现在DOM中。 - JordanBarber