
Vue实现选项卡功能
发布日期:2021-05-07 23:04:18
浏览次数:9
分类:原创文章
本文共 1425 字,大约阅读时间需要 4 分钟。
Vue实现选项卡功能
select.vue组件
<template> <div class="select"> <!-- 按钮 --> <div class="btn"> <span v-for="item in 4" :class="{active:item===idx}" @click="selectState(item)" :key="item" >图片{ { item}}</span> </div> <!-- 图片区域 --> <div class="imgBox"> <img v-for="(item,index) in imgs" :style="{display:idx===index+1?'block':'none'}" :key="item" :src="item" alt /> </div> </div></template><script>export default { props: { //图片 images: { type: Array, default() { return [ require("../assets/img1.jpg"), require("../assets/img2.jpg"), require("../assets/img3.jpg"), require("../assets/img4.jpg") ]; } } }, data() { return { //选中的索引 idx: 1, //相应的图片 imgs: [] }; }, created() { this.imgs = this.images; }, methods: { //改变选中状态 selectState(item) { this.idx = item; } }};</script><style scoped>/* 按钮 */.select .btn { display: flex;}.select .btn span { width: 25%; height: 1.333333rem; background-color: azure; text-align: center; line-height: 1.333333rem; font-size: 0.426667rem;}.select .btn .active { background-color: chocolate;}/* 图片 */.select .imgBox{ height: 12.666667rem;}.select .imgBox img{ width: 100%; height: 100%;}</style>
具体看githup链接:
https://github.com/await-lfq/vuePlugin.git
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年04月04日 22时21分22秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
2020第十五届全国大学生智能汽车竞赛——4X4矩阵键盘+Flash调参系统
2021-05-08
合并两个有序数组
2021-05-08
Ubuntu 环境下使用中文输入法
2021-05-08
小白学习Vue(?)--model选项的使用(自定义组件文本框双向绑定)
2021-05-08
聊聊我的五一小假期
2021-05-08
面向对象之异常处理:多路捕获
2021-05-08
Python简易五子棋
2021-05-08
MySQL8.0.19 JDBC下载与使用
2021-05-08
Windows安装MongoDB 4.2.8
2021-05-08
Vue新建项目——页面初始化
2021-05-08
Cent OS 7.6 服务器软件安装(这篇博客主要是为了方便我配置云主机的)
2021-05-08
MySQL使用系列文章
2021-05-08
Node.js包使用系列(一)——修改NPM全局下载和缓存路径
2021-05-08
TDengine使用(一)——TDengine下载与安装
2021-05-08
Node.js包使用系列(三)——常用npm包列表
2021-05-08
ubuntu和windows之间无法复制粘贴
2021-05-08
编译Linux内核--制作文件系统--远程调试程序
2021-05-08
启动加载器BootLoader
2021-05-08
力扣239. 滑动窗口最大值
2021-05-08
史上最全Vue的组件传值
2021-05-08