I'm trying to understand the use case of <template> and it's functions. Having referenced the docs, I'm still left fairly confused.
考虑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>
Run Code Online (Sandbox Code Playgroud)
我们为什么会用<template>,而不是只是一个简单的<div>,以及如何使用<template>比说的不同,使用<custom-component>?
我正在尝试将密钥添加到对象(如果不存在),或者增加其计数(如果已经存在)。如果新密钥不存在,以下代码将正确添加新密钥,但如果已经存在,则不会增加其数量。而是返回{UniqueResult1:NaN, UniqueResult2:NaN}。
let detectionHash = {};
function onDetected(result) {
detectionHash[result.code]++;
if(detectionHash[result.code] >= 5) {
//here's where I want to be
}
}
Run Code Online (Sandbox Code Playgroud)
如果密钥已经存在,如何增加密钥的数量?