[英]Icons instead of text as tabs in Vue.js
I wanted to make the lower menu similar to VK, where you click on the icons and the content changes.我想把下面的菜单做成类似于 VK,你点击图标,内容就会改变。 I implemented different content, but I can't make each tab have its own icon.
我实现了不同的内容,但我无法让每个选项卡都有自己的图标。
I provide a screenshot and code.我提供了截图和代码。 Do not pay attention to the style, I first need to understand the logic Using Vue CLI.
不关注样式,我首先需要了解使用Vue CLI的逻辑。
<template>
<div id="app">
<font-awesome-icon
icon="user-secret"
v-for="tab in tabs"
:key='tab'
@click="currentTab = tab"
:class="['tab-button', {active: currentTab === tab}]"
>
{{ tab }}
</font-awesome-icon>
<component v-bind:is="currentTabComponent"></component>
</div>
</template>
<script>
import Posts from './Posts.vue'
import List from './List.vue'
export default {
data () {
return {
currentTab: 'Posts',
tabs: ['Posts', 'List'],
icon: 'bell'
}
},
components: {
tabPosts: Posts,
tabList: List
},
computed: {
currentTabComponent() {
return 'tab-' + this.currentTab.toLowerCase()
}
}
}
</script>
<style scoped>
body {
overflow: auto;
padding: 0;
margin: 0;
}
#app {
position: relative;
width: 320px;
height: 400px;
border: solid 1px black;
}
.tab-button.active {
position: relative;
color: red;
height: 50px;
width: 50px;
}
.tab-button {
position: relative;
float: right;
bottom: 10px;
height: 50px;
width: 50px;
}
</style>
Try this:尝试这个:
<div
v-for="tab in tabs"
:key='tab'
@click="currentTab = tab"
:class="['tab-button', {active: currentTab === tab}]"
>
<font-awesome-icon >
icon="user-secret"
</font-awesome-icon >
</div>
also this @click="currentTab = tab"
needs to be refactored这个
@click="currentTab = tab"
也需要重构
I'l assume that this issue has already been solved, but, in any case, here is my contribuition using fontAwesome so you can understand the logic:我假设这个问题已经解决了,但是无论如何,这是我使用 fontAwesome 的贡献,因此您可以理解逻辑:
Change the definition of your data tabs
and currentTab
to something like this:将数据
tabs
和currentTab
的定义更改为如下所示:
currentTab: {title:'Post section',icon:'bell',page:'Post'},
tabs:{
title:'Post section',
icon:'bell',
page:'Post'
},{
title:'List of posts',
icon:'list',
page:'List'
}
Convert your font-awesome-icon
tag to:将您的
font-awesome-icon
标签转换为:
<button v-for="tab in tabs" :key="tab" :class="['tab-button', { active: currentTab === tab }]" @click="currentTab = tab" title="tab.title"><i class="fa" :class="'fa-'+tab.icon"></i></button>
Finally change you component
tag to最后将您的
component
标签更改为
<component :is="currentTab.page" class="tab"></component>
and them you can ignore the whole compuded: {}
section of your export default
并且你可以忽略整个
compuded: {}
export default
部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.