简体   繁体   English

在“AirJordan”和“NewBalance”标签之间添加一个空格 - VUEJS

[英]Adding a space between the words "AirJordan" and "NewBalance" tabs - VUEJS

I have a v-for and transition for a tab nav.我有一个用于标签导航的 v-for 和转换。 I would like to add a space between the words "Air(space here)Jordan" and "New(space here)Balance" in the code below.我想在下面的代码中在“Air(space here)Jordan”“New(space here)Balance”之间添加一个空格。 Im using vue3 and tailwindcss.我正在使用 vue3 和 tailwindcss。 Its importing the component but when adding a space in thee desired words, it wont use the component anymore.它正在导入组件,但是在您想要的单词中添加空格时,它将不再使用该组件。

data() {
  return {
    currentTab: 'Adidas',
    tabs: ['Adidas', 'Airjordans', 'Nike', 'Newbalance', 'Reebok', 'Converse', 'Vans', 'Puma']
  }
}, }

my template code is shown below.我的模板代码如下所示。

    <div class="nav">
      <div class="bg-[#f3f4f6]">
      <div class="max-w-7xl flex flex-1 overflow-auto whitespace-nowrap pl-4 pr-4 lg:pl-10 py-3 space-x-4 ">
      <button  class="font-rubikreg uppercase text-sm "
         v-for="tab in tabs"
         :key="tab"
         :class="['tab-button', { active: currentTab === tab } ]"
         @click="currentTab = tab"
       >
        {{ tab }}
      </button>
    </div>

i am importing components to display under each tab name.我正在导入要在每个选项卡名称下显示的组件。 Then pushing to display when name is clicked.然后在单击名称时推送以显示。 How can i add a space in NewBalance and AirJordans.如何在 NewBalance 和 AirJordans 中添加空间。

  import Airjordans from "./airjordans.vue";
  import Nike from "./nike.vue";
  import Adidas from "./adidas.vue";
  import Newbalance from "./newbalance.vue";
  import Reebok from "./reebok.vue";
  import Converse from "./converse.vue";
  import Vans from "./vans.vue";
  import Puma from "./puma.vue";

The best way is to separate the components from the labels.最好的方法是将组件与标签分开。 Alternatively you could try to do some hack, but I'd say being explicit is better.或者,您可以尝试做一些技巧,但我会说明确更好。

If you look into the docs they show an example where they have an object of with the keys and Components matching如果您查看文档,他们会显示一个示例,其中他们有一个 object 的键和组件匹配

link 关联

const tabs = {
  Home,
  Posts,
  Archive
}

you can setup a similar thing, just define the key您可以设置类似的东西,只需定义键

example: link示例: 链接

const tabs = {
  "H O M E": Home,
  Archive,
  Posts,
}

My preference, however, would be to be more explicit and use an array like this但是,我的偏好是更明确并使用这样的数组

const tabs = [
  {label: 'Adidas', component: Adidas},
  {label: 'Air jordans', component: AirJordans},
  // etc...
];

and then have currentTab use the index然后让currentTab使用索引

full example link完整示例链接

<script>
  import { ref } from 'vue'
  import Adidas from './Adidas.vue';
  import AirJordans from './AirJordans.vue';

  const tabs = [
    {label: 'Adidas', component: Adidas},
    {label: 'Air jordans', component: AirJordans},
  ];
  
  export default {
    data() {
      return {
        currentTab: 0,
      }
    },
    setup(){
      return {tabs}
    }
  }
</script>
<template>
  <button v-for="(tab,i) in tabs" :key="i" @click="currentTab=i" :class="{ active: currentTab === i }">
    {{tab.label}}
  </button>
  <component v-bind:is="tabs[currentTab].component"></component>
</template>
<style>
  .active{
    background: salmon;
  }
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM