小黑记事本

学习地址:https://www.bilibili.com/video/BV12J411m7MG?p=18

效果展示:

 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>小黑记事本</title>
    <link rel="stylesheet" href="css/note.css">
    
</head>
<body>
    <div class="box" id='app'>
        <div class="header">
            <h1>小黑记事本</h1>
            <input type="text" placeholder="请输入任务" v-model='msg'
             @keyup.enter='add'>
        </div>
        <div class="body">
            <ul>
                <li v-for='(item,index) in msgArr'>
                    <div class='message'>
                        <span>{{index+1}}</span>
                        <label for="">{{item}}</label>
                        <button @click='remove(index)'>X</button>
                    </div>
                </li>
            </ul>
        </div>
        <div class="footer">
            <img src="img/logo.png" alt="">
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script src='js/node.js'></script>
     
</body>
</html>

css代码:

* {
    padding: 0;
    margin: 0;
}
.box {
    width: 300px;
    /* background-color: grey; */
    margin: 40px auto 0;
}
h1 {
    font-weight: normal;
    color: coral;
    font-size: 28px;
    text-align: center;
    
}
input {
    width: 300px;
    height: 30px;
    outline: none;
    padding-left: 2px;
    margin: 20px 0 0;
}
ul {
    background-image: url(../img/bg.png);
}
li {
    list-style: none;
    border-bottom: 1px solid grey;
}
.message {
    margin: 5px 0;
    width: 100%;
}
button {
    display: none;
    float: right;
    padding-right: 30px;
    width: 20px;
    height: 25px;
    border: none;
    background-color: transparent;
    font-size: 14px;
    outline: none;
}
li:hover button {
    display: block;
}
button:hover{
    color: rgb(243, 83, 43);
}
r
.footer {
    text-align: center;
    margin-top: 30px;
}
img {
    width: 50%;
}

js代码:

var app = new Vue({
    el:'#app',
    data:{
        msg:'',
        msgArr:[]
    },
    methods:{
        add:function(){
            // console.log(this.msg);
            this.msgArr.push(this.msg);
            // console.log(this.msgArr);
            this.msg=''
        },
        remove:function(index){
            // console.log(index);
            this.msgArr.splice(index,1)
        }
    }
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
小黑记事本是一个使用Vue框架编写的项目,实现了简易的记事本功能。下面是部分小黑记事本的Vue源代码: 模板部分: ```html <template> <div class="notebook"> <h1>小黑记事本</h1> <div class="input-container"> <textarea v-model="content" placeholder="开始编写"></textarea> </div> <div class="button-container"> <button @click="saveNote">保存</button> <button @click="clearNote">清空</button> </div> <div class="notes-container"> <h2>已保存的笔记</h2> <ul> <li v-for="(note, index) in notes" :key="index">{{ note }}</li> </ul> </div> </div> </template> ``` 脚本部分: ```javascript <script> export default { data() { return { content: '', notes: [], }; }, methods: { saveNote() { if (this.content.trim() !== '') { this.notes.push(this.content.trim()); this.content = ''; } }, clearNote() { this.content = ''; }, }, }; </script> ``` 样式部分: ```css <style scoped> .notebook { text-align: center; margin: 20px auto; } .input-container { margin-bottom: 20px; } textarea { width: 300px; height: 150px; } .button-container button { margin: 0 10px; } .notes-container { margin-top: 30px; } ul { list-style-type: none; padding-left: 0; } li { margin-top: 10px; } </style> ``` 以上是小黑记事本的一个简化版本,实现了输入内容的保存和清空,并将已保存的笔记展示在界面上。用户可以在文本框中输入内容,点击保存按钮即可将内容添加到已保存的笔记列表中。点击清空按钮可以清空文本框中的内容。小黑记事本提供了简单的界面交互,方便用户保存和管理笔记。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值