美文网首页
06-组件化todo、选项卡、下拉菜单

06-组件化todo、选项卡、下拉菜单

作者: 云桃桃 | 来源:发表于2019-07-25 23:58 被阅读0次
3.gif
  • practice.vue
<template>
    <div class="practice-list">
        <section class="todo-box">
            <practiceTitle title="待办TODO列表"></practiceTitle>
            <todoHeader @newVal="receiveVal"></todoHeader>
            <todoNowork :todoArr="todoArr" @newFinishItem="newFinishArr"></todoNowork>
            <todoFinish  :todoArr="finishTodoArr"></todoFinish>
        </section>
        <section class="">
            <practiceTitle title="选项卡"></practiceTitle>
            <tabTitle @changeIndex="receiveTabIndex" :tabArr="tabArr"></tabTitle>
            <tabContent :tabActiveIndex="tabActiveIndex" :tabArr="tabArr"></tabContent>
        </section>
        <section class="">
            <practiceTitle title="下拉菜单"></practiceTitle>
            <dropMenu :dropArr="dropMenuArr"></dropMenu>
        </section>

    </div>
</template>

<script>
    import practiceTitle from '../views/practiceTitle.vue'
    import todoHeader from '../views/todo/header.vue'
    import todoNowork from '../views/todo/nowork.vue'
    import todoFinish from '../views/todo/finish.vue'
    import tabTitle from '../views/tab/tabTitle.vue'
    import tabContent from '../views/tab/tabContent.vue'
    import dropMenu from '../views/dropMenu/dropMenu.vue'

    export default {
        name: 'Practice01',
        components: {practiceTitle, todoHeader, todoNowork, todoFinish, tabTitle, tabContent,dropMenu},
        data() {
            return {
                todoArr: [],
                finishTodoArr: [],
                tabArr: [{
                    "title": "河南",
                    "content": "走回强周律管地流中按写段列军压上。"
                }, {
                    'title': '江西',
                    'content': '特气采以派式到式里极极元我圆红发。用别器法地南件过变品布还打导土术连。'
                }, {
                    'title': '海南',
                    'content': '江收来们立影红来七始能情才。机会七产习需存电建手全别每响例段己。空加光各改自层和又件路必成家。'
                }],
                tabActiveIndex: 0,
                dropMenuArr:[
                    {name:'首页',children:[]},
                    {name:'我要出借',children:['出借计划','出借列表']},
                    {name:'我要借款',children:['我要借款','我要还款']},
                    {name:'我的账户',children:['出借账户','借款账户']},
                    {name:'关于我们',children:[]}
                ]
            }
        },

        methods: {
            receiveVal: function (item) {
                this.todoArr.unshift(item);
            },
            newFinishArr: function (item) {
                this.finishTodoArr.push(item);
            },
            receiveTabIndex: function (index) {
                this.tabActiveIndex = index;
            }
        },
        computed: {},
    }
</script>
  • 引入组件.vue
//practiceTitle.vue
<template>
   <h2>{{title}}</h2>
</template>

<script>
    export default {
        name: "practiceTitle",
        props:['title']
    }
</script>

<style scoped>

</style>

// nowork.vue
<template>
    <div>
        <h3>待完成({{todoArr.length}})</h3>
        <ul>
            <li v-for="(item,index) in todoArr" :key="index" class="clear"><input class="fl" type="checkbox" @click="dealItem(index,item)" v-model="checked">第{{index+1}}项:{{item.val}}<span @click="deleteItem(index)" class="delete-todo-icon">删除</span></li>
        </ul>
        <p class="txt-white" v-if="!todoArr.length">暂无待办内容!</p>
    </div>
</template>
<script>
    export default {
        // 从父级接收的值
        props:['todoArr'],
        data:function(){
            return {checked:false}
        },
        methods:{
            /**
             * 删除项
             * @param index
             * @param status
             */
            deleteItem:function (index) {
                this.todoArr.splice(index,1);
            },
            /**
             * 处理待办和完成项
             * @param index
             * @param item
             * @param status
             */
            dealItem:function (index,item) {
                    this.todoArr.splice(index,1);
                    this.$emit('newFinishItem',{val:item.val,checked:true});

            }
        }

    }
</script>



// finish.vue 
<template>
    <div class="finish-todo">
        <h3>已完成({{todoArr.length}})</h3>
        <ul>
            <li v-for="(item,index) in todoArr" :key="index" class="clear"><input class="fl" type="checkbox" @click="dealItem(index,item)" v-model="checked">第{{index+1}}项:{{item.val}}<span @click="deleteItem(index)" class="delete-todo-icon">删除</span></li>
        </ul>
        <p class="txt-white" v-if="!todoArr.length">暂无已完成内容!</p>

        <todoFoot v-bind="$attrs"></todoFoot>
    </div>


</template>
<script>
    import todoFoot from './foot.vue'
    export default {
        // 从父级接收的值
        props:['todoArr'],
        components:{todoFoot},
        data:function(){
            return {checked:true}
        },
        created(){
            // console.log(this.$attrs);
        },

        methods:{
            /**
             * 删除项
             * @param index
             * @param status
             */
            deleteItem:function (index) {
                this.todoArr.splice(index,1);
            },
            /**
             * 处理待办和完成项
             * @param index
             * @param item
             * @param status
             */
            dealItem:function (index,item) {
                    this.todoArr.splice(index,1);
                    this.$emit('newFinishArr',{val:item.val,checked:true});
                    this.finishTodoArr.push();

            }
        }

    }
</script>

<style scoped>

</style>


// header.vue
<template>
    <div>
    <input type="text" v-model="addTodoVal" v-on:keyup="addItem($event)">
    </div>
</template>
<script>
    export default {
        // name: "Header",
        data:function(){
            return {
                addTodoVal:''
            }
        },
        methods:{
            /**
             * 增加待办项
             * @param event
             */
            addItem:function (event) {
                if(event.keyCode==13){
                    if(/\s/.test(this.addTodoVal) || !this.addTodoVal){
                        console.log('不能为空或者包含空格!');
                        return;
                    }
                    this.$emit('newVal', {val:this.addTodoVal+' 创建时间:'+(new Date().toLocaleString()),checked:false});
                    this.addTodoVal='';
                }
            }
        }
    }
</script>

<style scoped>

</style>

//dropMenu.vue
<template>

    <div class="drop-box">
        <ul class="drop-ul clear">
            <li   v-for="(item,index) in dropArr"><a class="drop-title" href="#">{{item.name}}</a>
                <ol v-if="item.children.length!=0"  class="child-ol">
                    <li v-for="child in item.children"><a href="#">{{child}}</a></li>
                </ol>
            </li>
        </ul>
    </div>
</template>

<script>
    export default {
        name: "dropMenu",
        props:['dropArr'],
        data(){
            return {activeIndex:0,childShowStatus:true}
        },
        methods:{
        }

    }
</script>

<style scoped>
.drop-ul li{float: left; position: relative;
    line-height: 30px;}
.drop-ul .drop-title{ font-size: 14px; padding: 0px 20px;  color: #333; text-decoration: none;}
.drop-ul li:hover .drop-title{color: #0000ee;}
.drop-ul li:hover .child-ol{display: block;}

.child-ol{display: none; position: absolute; top:30px;
    left: 0px;
    background-color: #00FF33;}
.child-ol li{width: 100%;
    text-align: center;
    line-height: 30px;}
.child-ol li a{font-size: 12px; color: #333;}
.child-ol.show{display: block;}

</style>


// tabContent.vue
<template>
    <div class="tab-content-box">
        {{tabArr[tabActiveIndex].content}}
    </div>
</template>

<script>
    export default {
        name: "tabContent",
        props:['tabArr','tabActiveIndex']
    }
</script>

// tabTitle.vue
<template>
    <ul class="tab-menu-box clear">
        <li v-for="(item,index) in tabArr" @click="changeActive(index)" :class="{active:index==qqTabActiveIndex}">{{item.title}}</li>
    </ul>

</template>

<script>
    export default {
        name: "tabTitle",
        props:['tabArr'],
        data(){
          return  {active:true,qqTabActiveIndex:0}
        },
        methods:{
            /**
             * 切换选项卡
             * @param index
             */
            changeActive(index){
                this.qqTabActiveIndex=index;
                this.$emit('changeIndex',this.qqTabActiveIndex);
            }
        }
    }
</script>

  • css,把样式写在了公共
.finish-todo input[type='checkbox']{background-color: #00aced;}
.delete-todo-icon{float: right;
    color: #00aced;
    cursor: pointer; font-size: 14px;
    line-height: 30px; padding: 0px 0px 0px 20px;
}

.practice-list h2{color: #fff; font-size: 24px;
    line-height: 44px;
    text-align: center;
    font-weight: bold;}
.todo-box h3{font-size: 18px;
    line-height: 30px; color: #fff;}
.todo-box li{line-height: 36px; font-size: 14px;
    color: #fff;}
.practice-list>section{padding:5px 20px;
    background-color: #999;
    margin-bottom: 15px;}
.txt-white{color: #fff;}

.tab-container {
    border: 1px solid #ddd;
    margin: 10px;

    padding: 10px;
}

.tab-menu-box li {
    float: left;
    line-height: 30px;
    padding: 0px 25px;
    border-top: 1px solid #edd;
    border-right: 1px solid #ddd;
    position: relative;
    cursor: pointer;
}

.tab-menu-box li.active {
    background-color: #007fff;
    color: #000;
}

.tab-menu-box li.active .close-btn {
    color: #fff;
}

.tab-menu-box li:first-child {
    border-left: 1px solid #ddd;
}

.tab-menu-box .tab-title {
    line-height: 30px;
    display: block;
    padding: 0px 10px;
}

.tab-menu-box .close-btn {
    position: absolute;
    right: 0px;
    top: 0px;
    right: 2px;
    color: #007fff;
    width: 16px;
    line-height: 16px;
    text-align: center;
}

.tab-menu-box .close-btn:hover {
    color: #fff;
    background-color: #007fff;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
}

.tab-content-box {
    border: 1px solid #ddd;
    padding: 10px;
}

相关文章

  • 06-组件化todo、选项卡、下拉菜单

    practice.vue 引入组件.vue css,把样式写在了公共

  • 常用技巧

    下拉菜单的制作 一级下拉菜单数据选项卡--数据验证--序列--选取对应来源二级下拉菜单①在公式选项卡名称管理器下添...

  • 第十九谈:下拉菜单

    本节课我们来开始学习 Bootstrap 的提供的下拉菜单组件。 一.下拉菜单 下拉菜单组件依赖于 Popper....

  • Vue - 嵌套组件(Nested Component)

    eg:item.vue todo.vue todo.vue包含item组件为嵌套组件。

  • 父作用域如何向子组件传递参数

    1.子组件:props:[todo] 2.在父中渲染的时候,给子组件绑定:todo="item"

  • 2018-01-10

    1 参考Input组件 得出最简单的 多行文本组件 TODO2: 添加label ?Todo3: 添加修改表单事件...

  • Bootstrap - 菜单1

    下拉菜单(基本用法)- 跳转页面 小伙伴们注意,在Bootstrap框架中的下拉菜单组件是一个独立的组件,根据不同...

  • html day2课堂总结

    02表单标签和input标签 03-下拉菜单和多行文本框 04-div和span 05-css基础 06-选择器 ...

  • Bootstrap(基础二)

    第5章 菜单、按钮及导航 一、下拉菜单 小伙伴们注意,在Bootstrap框架中的下拉菜单组件是一个独立的组件,根...

  • Vue中判断点击是否在组件外

    自己使用div模拟select,有如下需求: 组件获得焦点时,自动弹出下拉菜单 鼠标点击下拉菜单时,下拉菜单不能收...

网友评论

      本文标题:06-组件化todo、选项卡、下拉菜单

      本文链接:https://www.haomeiwen.com/subject/pbllrctx.html