How to show short string inside tab-content of vue-form-wizard but display full string inside component's prop

huangapple go评论70阅读模式
英文:

How to show short string inside tab-content of vue-form-wizard but display full string inside component's prop

问题

我想在 vue-form-wizardtab-content 中显示简短文本,但在组件的属性中显示完整文本。

tab-content 应显示国家缩写,例如USA,UK,UAE等,而组件应将完整名称作为属性。

以下是我的代码:

<template>
  <form-wizard>
    <tab-content
      v-for="country in countries"
      :key="country.id"
      :title="country.title"
    >
      <component
        :is="country.name"
        :title="country.title"
      />
    </tab-content>
  </form-wizard>
</template>

<script>
export default {
  data() {
    return {
      countries: [
        {
          id: 0,
          title: 'United States',
          name: 'UnitedStates',
        },
        {
          id: 1,
          title: 'United Kingdom',
          name: 'UnitedKingdom',
        },
        {
          id: 2,
          title: 'United Arab Emirates',
          name: 'UnitedArabEmirates',
        },
      ],
    }
  },
}
</script>
英文:

I want to display short text inside tab-content of vue-form-wizard but display full text inside component's prop.

tab-content should display countries abbreviation, e.g. USA, UK, UAE etc. whereas the component should take full name as prop.

Here is my code:

&lt;template&gt;
  &lt;form-wizard&gt;
    &lt;tab-content
      v-for=&quot;country in countries&quot;
      :key=&quot;country.id&quot;
      :title=&quot;country.title&quot;
    &gt;
      &lt;component
        :is=&quot;country.name&quot;
        :title=&quot;country.title&quot;
      /&gt;
    &lt;/tab-content&gt;
  &lt;/form-wizard&gt;
&lt;/template&gt;

&lt;script&gt;
export default {
  data() {
    return {
      countries: [
        {
          id: 0,
          title: &#39;United States&#39;,
          name: &#39;UnitedStates&#39;,
        },
        {
          id: 1,
          title: &#39;United Kingdom&#39;,
          name: &#39;UnitedKingdom&#39;,
        },
        {
          id: 2,
          title: &#39;United Arab Emirates&#39;,
          name: &#39;UnitedArabEmirates&#39;,
        },
      ],
    }
  },
}
&lt;/script&gt;

答案1

得分: 1

这里是使用短名称的变种。

<div id="app">
  <form-wizard>
    <tab-content
      v-for="country in countries"
      :key="country.id"
      :title="shortName(country)"
    >
      {{country.title}}
    </tab-content>
  </form-wizard>
</div>

使用:

countries: [
  {
    id: 0,
    title: 'United States',
    name: 'UnitedStates',
    short: 'US'
  },

methods: {
  shortName(country) {
    return country.short
  }
}

这里是JSFiddle

在步骤内部没有插槽用于提供自定义内容。您只能提供一个图标来代替步骤编号,就像在这个演示中一样。

英文:

Here is a variant with the short names.

&lt;div id=&quot;app&quot;&gt;
&lt;form-wizard&gt;
    &lt;tab-content
      v-for=&quot;country in countries&quot;
      :key=&quot;country.id&quot;  
      :title=&quot;shortName(country)&quot;
    &gt;
      {{country.title}}
    &lt;/tab-content&gt;
  &lt;/form-wizard&gt;
&lt;/div&gt;

using:

 countries: [
    {
      id: 0,
      title: &#39;United States&#39;,
      name: &#39;UnitedStates&#39;,
      short: &#39;US&#39;
    },

and

methods: {  	
  	shortName(country) {
    	return country.short
    }
  }

Here is the JSFiddle

There is no slot inside the step to provide a custom content. You can only provide a icon instead of the step number. Like in this Demo

huangapple
  • 本文由 发表于 2023年3月9日 20:34:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定