英文:
How to show short string inside tab-content of vue-form-wizard but display full string inside component's prop
问题
我想在 vue-form-wizard 的 tab-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:
<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>
答案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.
<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>
using:
countries: [
{
id: 0,
title: 'United States',
name: 'UnitedStates',
short: 'US'
},
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论