Vue简单组件tab选项卡

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选项卡组件</title>
    <script src="vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #nav ul{
            list-style: none;
        }
        #nav ul li{
            display: inline-block;
            width:100px;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
            text-align: center;
            border:2px solid #ffff00;
            box-sizing: border-box;
        }
        .pink{
            background-color: pink;
        }
        .blue{
            background-color: #0086b3;
        }
        #div{
            width:500px;
            height:300px;
            font-size: 30px;
            text-align: center;
            line-height: 300px;
            background-color: #718c00;
        }
    </style>
</head>
<body>
<div id="app">
    {{name}}
    <test></test>
</div>
<template id="tp1">
    <div id="nav">
        <ul>
            <li v-for="item in array" @click="choose(item)" :class='content===item?"pink":"blue"'>{{item}}</li>
        </ul>
        <div id="div">{{content}}</div>
    </div>
</template>
<script>
    //创建一个组件
    var component=Vue.extend({
       template:"#tp1",
        data:function () {
            return{
              content:"北京",
              array:["北京","上海","杭州","广州","深圳"]
           }
        },
        methods:{
           choose:function (item) {
            this.content=item;
           }
        }
    });
    //注册一个组件
    Vue.component("test",component);
    new Vue({
        el:"#app",
        data:{
            name:"选项卡组件案例"
        }
    });
</script>
</body>
</html>

结果截图(点相应的标题,下面会出现不同的内容)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值