vue记事本小案例

这是一个使用Vue.js创建的简单记事本应用。HTML结构包含输入框和列表,用于添加和删除条目。Vue实例绑定了数据和方法,如`add`用于添加记事,`remove`用于删除,`clear`用于清空所有记事。应用具有响应式布局和基本的样式设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vue和HTML结构

<!DOCTYPE html>
<html lang="zh-cn">

<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" />
  <link rel="stylesheet" href="./css/index.css" />
  <title>记事本</title>
</head>

<body>
  <div id="app">
    <h2>记事本</h2>
    <div class="main">
      <input type="text" v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入内容!" />
      <ul>
        <li>
          <!-- 使用v-for更具数据生成列表结构 -->
          <div class="content" v-for="(item,index) in list">
            <span >{{index+1}}.{{item}}</span>   <!--用{{index+1}}显示数据的索引以及数据的每一项-->
            <button @click="remove(index)">❌</button> 
          </div>
          
        </li>
      </ul>
      <p class="empty">空空如也...</p>
    </div>
    <div class="bottom">
      <span>合计:{{list.length}}</span>
      <span @click="clear()">清空</span>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
        list: ['吃饭','写代码','睡觉'],
        

      },
      methods: {
        add () {//添加数据的方法,使用v-on和keyup.enter事件绑定
          this.list.push(this.inputValue)  
        },
        remove(index){//删除数据方法
          this.list.splice(index,1);
        },
        clear(){
          this.list=[];//清空list
        }
      },
    })
  </script>
</body>

</html>

css样式

#app {
  text-align: center;
  background: #fbebd4;
  width: 480px;
  max-height: 400px;
  box-sizing: border-box;
  padding-top: 50px;
  border-radius: 5px;
  position: relative;
}

#app h2 {
  margin: 0;
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: #6a4d52;
  font-size: 30px;
}

#app .main {
  max-height: 300px;
  width: 454px;
  margin: 5px auto 0;
  transform: translateX(1px);
}

#app ul {
  padding: 0;
  max-height: 200px;
  overflow-y: scroll;
  margin-bottom: 0;
}

#app ul::-webkit-scrollbar {
  width: 0 !important;
}

#app li {
  list-style: none;
  border-bottom: 1px solid #6a4d52;
  text-align: left;
  box-sizing: border-box;
  cursor: pointer;
  font-size: 25px;
  color: #8895a8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  line-height: 40px;
  display: block;
}

#app li:hover {
  background-color: #fcfaed;
}

#app li span {

  color: #6a4d52;
}

#app button {
  margin-left: 300px;
  cursor: pointer;
  border: none;
  background-color: transparent;
}

#app input {
  height: 30px;
  font-size: 20px;
  appearance: none;
  outline: none;
  border: none;
  padding-left: 5px;
  box-sizing: border-box;
  border-radius: 5px;
  color: #6a4d52;
}

#app .bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  padding: 0 14px;
}

#app .bottom span {
  color: #929093;
}

#app .bottom span:last-child {
  cursor: pointer;
  color: #935256;
}

#app p {
  color: #929093;
  font-size: 20px;
  margin: 0;
  padding: 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值