vuejs学习系列-第一个小demo

现在上节中安装的项目的src目录中建立pages文件用来装demo源码
我们现在的目录结构是这样的
这里写图片描述

首先在pages里新建demo01文件夹,顺便在demo01下,建立index.vue文件,然后在router里添加

{
    path: '/demo01',
    name: 'DEMO01',
    component: demo01
  }

index.vue里将会放置我们所有的demo代码
首先,写html结构作为template

<template>
    <div id="demo01">
        <div class="table">
            <ul>
                <li v-for="item in dataList"><span class="text">{{item.name}}</span><span class="slide"><div class="progrss"><i class="progrss-activ" :style="{width: item.score + '%'}"></i></div><span class="num">{{item.score}}</span></span></li>
            </ul>
            <div class="ragle">
                <div class="input-item" v-for="(item, index) in dataList">
                    <label :for="'inpt'+(index+1)">
                    {{item.name}}
                    </label>
                    <input type="range" :data-index="index" v-on:input="rangeChange" :id="'inpt'+(index+1)" :value="item.score" max="100" min="0" step="1"/>
                    <span>{{item.score}}</span>
                </div>
            </div>
        </div>

    </div>
</template>

结构很简单,一个是进度条,一个是拉动条,稍微加点样式

<style>
    .table{
        height: 400px;
        width: 800px;
        margin: 100px auto;
        padding: 50px;
        background: #f5f5f5;
    }
    .table ul{
        width: 600px;
        margin: 0 auto;
    }
    .table ul li{
        height: 30px;
        line-height: 30px;
        margin-top: 30px;
        overflow: hidden;
        position: relative;
    }
    .text, .slide{
        display: inline-block;
        position: absolute;
    }
    .text{
        left: 0;
        width: 10%;
        text-align: right;
    }
    .slide{
        width: 90%;
        left: 12%;
    }
    .progrss{
        width: 80%;
        background: #dedede;
        height: 30px;
        display: inline-block;
        position: relative;
        border-radius: 8px;
    }
    .progrss-activ{
        height: 100%;
        background: #00A2E8;
        display: block;
        border-radius: 8px;
    }
    .num{
        display: inline-block;
        height: 30px;
        line-height: 30px;
        position: absolute;
        right: 0;
        top:0;
        width: 40px;
    }
    .ragle{
        margin: 50px 100px;
    }
    .input-item{
        height: 40px;
    }
    .input-item input{
        width: 80%;
        outline: none
    }
    .input-item .span{

    }
</style>

接下来就是写js了,在index.vue中添加script

<script>
    export default{
        data () {
            return {
                //首先定义数据
                dataList:[
                    {
                        "name": '语文',
                        "score": 87
                    },{
                        name: '数学',
                        score: 65
                    },{
                        name: '英语',
                        score: 96
                    },{
                        name: '体育',
                        score: 50
                    }
                ]
            }
        },
        created: function () {
            // console.log(this)
            // this.dataList = this.sortArray(this.dataList, 'score')
        },
        methods: {
            rangeChange: function (e) { //响应js时间
                var val = e.target.value;
                var index = e.target.attributes['data-index'].value
                console.log(val, index)
                this.dataList[index].score = val
                // this.dataList = this.sortArray(this.dataList, 'score')
            },
            sortArray: function (value, key) { //用来数据排序
              return value.sort(function (a, c) {
                return a[key] < c[key];
                })
            }
        }
    }
</script>

最终的效果就是
demo01效果

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪月青

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值