vue实现王者列表

展示王者荣耀中的人物能力信息列表数据

1.页面展示:

2.功能说明

1)展示出所有的王者的基本信息(表格)

2)点击“添加英雄”按钮打开添加页面

3)在添加页面点击“提交”按钮将添加的数据显示到页面表格中

4)点击“删除英雄”按钮按照倒序的方式进行删除

3.开发步骤

a)创建html页面

b)页面元素布局

c)样式美化处理

d)页面数据展示及效果处理

e)事件实现功能

4.代码 

css样式:

<style type="text/css">
/* 表格容器样式 */
.tableContain{
width: 70%;
margin: 50px auto;
}
/* 表格按钮容器样式 */
.btnCon{
width: 210px;
margin: 30px auto;
}
/* 表格按钮样式 */
.btnCon button{
width: 90px;
outline: none;
background-color: green;
border: 0px;
color: white;
height: 30px;
border-radius: 3px;
letter-spacing: 1px;
}
/* 遮罩层样式 */
.bj{
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-color: black;
opacity: 0.4;
}
/* 添加英雄的样式 */
.addList{
position: absolute;
width: 500px;
height: 300px;
top: 50px;
left: 35%;
z-index: 100;
background-color: #f1f1f1;
text-align: center;
border-radius: 3px;
}
/* 提交按钮样式 */
.addList button{
width: 190px;
background-color: yellowgreen;
border: 0px;
height: 30px;
border-radius: 3px;
letter-spacing: 1px;
}
ul{
margin: 5px auto 30px;
width: 85%;
border-top: 1px solid hsl(147, 99%, 52%);
}
li{
height: 30px;
line-height: 30px;
margin-top:8px;
list-style: none;
}
</style>

html文件:

<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入js文件 -->
    <script src="js/vue2.js"></script>
</head>
<body>
    <!-- 管理区域 -->
    <div id="box">
         <!-- 管理表格的div -->
        <div class="tableContain">
            <!-- 管理按钮的div -->
            <div class="btnCon">
                <button @click="addHreo()">添加英雄</button>
                <button @click="delHreo()">删除英雄</button>
            </div>
            <!-- 创建表格 -->
            <table border="1" style="border-collapse: collapse;" width="80%">
                <tr>
                <th>序号</th>
                <th>英雄名称</th>
                <th>熟练度</th>
                <th>评分</th>
                <th>位置</th>
                </tr>
                <!-- 绑定数据 -->
                <tr v-for="(hreo, index) in hreos" align="center">
                    <td>{{index}}</td>
                    <td>{{hreo.HeroName}}</td>
                    <td>{{hreo.slDo}}</td>
                    <td>{{hreo.pingF}}</td>
                    <td>{{hreo.local}}</td>
                </tr>
            </table>
        </div>
        <!-- 添加英雄的div -->
        <div>
            <!-- 遮罩层div -->
            <div class="bj" v-show="isShow"></div>
            <!-- 添加列表的div -->
            <div class="addList" v-show="isShow">
                <h3>添加英雄</h3>
                <!-- 无序列表(添加数据) -->
                <ul>
                    <li>英雄名称:<input type="text" v-model="item.HeroName" /></li>
                    <li>熟练度:<input type="text" v-model="item.slDo"/></li>
                    <li>评分:<input type="text" v-model="item.pingF"/></li>
                    <li>位置:<input type="text" v-model="item.local"/></li>
                </ul>
                <button @click="submit()">提交</button>
            </div>
        </div>
    </div>
    <!-- 自定义脚本 -->
    <script>
        // 创建对象
        var vm = new Vue({
            el: '#box',
            data: {
                isShow: false,
                item:{ // 对象属性
                HeroName:'',
                slDo:'',
                pingF:'',
                local:''
            },
            hreos: [ // 数组中是一个一个的独立对象
                {
                    HeroName:'吕布',
                    slDo:'******',
                    pingF:'89',
                    local:'对抗路'
                },
                {
                    HeroName:'老夫子',
                    slDo:'****',
                    pingF:'80',
                    local:'对抗路'
                },
                {
                    HeroName:'瑶妹',
                    slDo:'**',
                    pingF:'100',
                    local:'发育路'
                },
                {
                    HeroName:'大乔',
                    slDo:'*****',
                    pingF:'60',
                    local:'中路'
                 }
              ]
            },
            methods: {
                addHreo(){
                    this.isShow = true
                },
                submit(){
                    // 将页面中输入的对象内容添加到数组中
                    this.hreos.push(this.item)
                    // 清除对象中的数据
                    this.item={ // 对象属性
                        HeroName:'',
                        slDo:'',
                        pingF:'',
                        local:''
                    }
                    // 隐藏添加信息
                    this.isShow = false
                },
                delHreo(){
                    // 将数组中的最后一个元素删除掉
                    this.hreos.pop()
                }
            },
        })
    </script>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值