vue.js怎么做选项卡 - 网站

vue.js怎么做选项卡

分类:Vue.js 答疑 - 常见问题 · 发布时间:2020-11-29 15:11 · 阅读:1171

本文环境:windows7、vue2.9.6,该方法适用于所有品牌的电脑。

vue.js做选项卡的方法:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Tab选项卡</title>
        <script src="js/vue.js"></script>
        <style>
            *{
                margin: 0px;
                padding: 0px;
            }
            #tab{
                width:420px;
                margin: 20px auto;
                position: relative;
            }
            #tab ul li{
                width: 100px;
                height: 30px;
                border: 1px solid #6699CC;
                float: left;
                list-style: none;
                text-align: center;
                line-height: 30px;
            }
            #tab ul li:first-child{
                border-right: none;
                border-radius: 10px 0px 0px 0px;
            }
            #tab ul li:last-child{
                border-left: none;
                border-radius: 0px 10px 0px 0px;
            }
            #tab ul .active{
                background-color:#6699CC;
                color:white;
            }
            #tab div{
                width: 415px;
                position: absolute;
                top: 32px;
                display: none;
            }
            #tab div img{
                width: 406px;
                border-radius:0px 0px 10px 10px;
            }
            #tab div.current{
                display: block;
            }
        </style>
    </head>
    <body>
        <div id="tab">
            <ul>
                <li v-on:mouseover="change(index)" :class="[currentindex==index?'active':'']":key="item.id"v-for="(item,index) in list">{{item.text}}</li>
            </ul>
            <div :class="[currentindex==index?'current':'']" v-for="(item,index) in list">
                <img :key="item.id" v-bind:src="item.imgsrc"/>
            </div>
        </div>
        <script>
            var vue1 = new Vue({
                el:'#tab',
                data:{
                    currentindex:'0',//当前选项卡的索引
                    list:[{
                        id:'1',
                        text:'春',
                        imgsrc:'img/1.jpg-600'
                    },{
                        id:'2',
                        text:'夏',
                        imgsrc:'img/2.jpg-600'
                    },{
                        id:'3',
                        text:'秋',
                        imgsrc:'img/3.jpg-600'
                    },{
                        id:'4',
                        text:'冬',
                        imgsrc:'img/4.jpg-600'
                    }]
                },
                methods:{
                    change:function(index){
                        this.currentindex=index;
                    }
                }
            });
        </script>
    </body>
</html>
标签:
vue.js 选项卡

相关文章

vue父子组件生命周期执行顺序是什么

执行顺序:父组件先创建,然后子组件创建;子组件先挂载,然后父组件挂载,即“父beforeCreate-&gt; 父create -&gt; 子beforeCreate-&gt; 子created -&gt; 子mounted -&gt; 父mounted”。

js原型和原型链是什么

js原型和原型链是:1、原型是一个可以被复制的一个类,通过复制原型可以创建一个一模一样的新对象;2、原型链是原型对象创建过程的历史记录,当访问一个对象的某个属性时,会先在这个对象本身属性上查找。

vue3.0有哪些新特性

vue3.0新特性有:1、性能比vue2.x更快;2、支持按需编译、体积更小;3、组合API,类似React Hooks;4、暴露了自定义渲染API;5、新增三个组件;6、更好地支持TS。

vue.js路由有什么用?

vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来。传统的页面应用,是用一些超链接来实现页面切换和跳转的;而在vue-router单页面应用中,则是路径之间的切换,也就是组件的切换。

vue.js能不能导入swiper?

vue.js中能导入swiper插件。方法:1、使用npm工具安装swiper;2、在组件中使用import语句加载插件并导入相关文件;3、在HTML内容中通过添加相关class类来搭建swiper框架和引入相关样式即可。

返回分类 返回首页