小编Mic*_*hał的帖子

What's the use of <template> within a <template> in VueJS 2?

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>

javascript templating vue.js vuejs2

4
推荐指数
3
解决办法
3420
查看次数

添加到JS对象或增加密钥(如果存在密钥)

我正在尝试将密钥添加到对象(如果不存在),或者增加其计数(如果已经存在)。如果新密钥不存在,以下代码将正确添加新密钥,但如果已经存在,则不会增加其数量。而是返回{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)

如果密钥已经存在,如何增加密钥的数量?

javascript increment

1
推荐指数
1
解决办法
385
查看次数

标签 统计

javascript ×2

increment ×1

templating ×1

vue.js ×1

vuejs2 ×1