Vue入门-使用Vue2完成简单的记事本Demo

news/2024/10/7 20:55:53/

需求:

①能够实现记录重复数据

②全部清空

③单条记录清空

页面效果:

代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vue2 记事本</title><style>body {font-family: Arial, sans-serif;}.note-container {max-width: 600px;margin: 0 auto;}textarea {resize: vertical;}</style>
</head><body><div id="app" class="note-container"><textarea v-model="noteContent" class="form-control"></textarea><div class="mt-3"><button @click="saveNote" class="btn btn-primary me-2">保存</button><button @click="clearNote" class="btn btn-secondary">清空</button></div><ul class="list-group mt-3" v-if="savedNotes.length > 0"><li class="list-group-item" v-for="note in savedNotes" :key="note">{{ note }}<button @click="deleteNote(note)" class="btn btn-danger btn-sm float-right">删除</button></li></ul></div><script src="js/vue.js"></script><script>new Vue({el: '#app',data: {noteContent: '',savedNotes: []},methods: {saveNote() {const note = this.noteContent.trim();if (note !== '') {this.savedNotes.push(note);localStorage.setItem('notes', JSON.stringify(this.savedNotes));this.noteContent = '';alert('笔记已保存!');}},clearNote() {this.noteContent = '';this.savedNotes = [];localStorage.removeItem('notes');},deleteNote(noteToDelete) {this.savedNotes = this.savedNotes.filter(note => note !== noteToDelete);localStorage.setItem('notes', JSON.stringify(this.savedNotes));}},mounted() {const savedNotes = localStorage.getItem('notes');if (savedNotes) {this.savedNotes = JSON.parse(savedNotes);}}});</script>
</body></html>


http://www.ppmy.cn/news/1535856.html

相关文章

Python运行态 - 代码调试:掌握pdb

简介&#xff1a;pdb&#xff08;Python Debugger&#xff09;是 Python 标准库中的调试工具&#xff0c;旨在帮助开发者在代码中设置断点、检查变量值和逐行执行代码。这对于定位和修复程序中的问题至关重要。pdb 是 Python 的内置模块&#xff0c;因此不需要额外安装。 历史…

(笔记)第三期书生·浦语大模型实战营(十一卷王场)–书生基础岛第3关---浦语提示词工程实践

学员闯关手册&#xff1a;https://aicarrier.feishu.cn/wiki/ZcgkwqteZi9s4ZkYr0Gcayg1n1g?open_in_browsertrue 课程视频&#xff1a;https://www.bilibili.com/video/BV1cU411S7iV/ 课程文档&#xff1a; https://github.com/InternLM/Tutorial/tree/camp3/docs/L1/Prompt 关…

MATLAB与R语言在建模中的合作与应用(上篇)

目录 目录 MATLAB 与 R 的优势比较 在建模中的互补性 数据预处理中的合作 1. 数据导入与清洗&#xff08;R语言&#xff09; 2. 数据格式转换与传递&#xff08;MATLAB&#xff09; 特征工程的协同使用 1. 特征生成&#xff08;MATLAB&#xff09; 2. 特征选择&#xf…

helm 测试安装redis

helm search repo redis # 搜索redis的chart helm show readme bitnami/redis # 展示安装相关文档&#xff08;readme文件&#xff09; 拉取指定版本的安装包&#xff08;chart&#xff09; helm pull bitnami/redis --version 17.4.3 解压安装包 tar -xf redis-17.4.3.tgz …

[C语言]指针和数组

目录 1.数组的地址 2.通过指针访问数组 3.数组和指针的不同点 4.指针数组 1.数组的地址 数组的地址是什么&#xff1f; 看下面一组代码 #include <stdio.h> int main() { int arr[5] {5,4,3,2,1}; printf("&arr[0] %p\n", &arr[0]); printf(&qu…

OpenCV视频I/O(13)视频采集类VideoCapture之等待多个视频流中的任意一个变为可用状态函数waitAny()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 等待来自 VideoCapture 的可用帧。 cv::VideoCapture::waitAny 是一个静态成员函数&#xff0c;用于等待多个视频流中的任意一个变为可用状态。这…

OpenGL笔记十九之相机系统

OpenGL笔记十九之相机系统 —— 2024-10-02 晚上 bilibili赵新政老师的教程看后笔记 code review! 文章目录 OpenGL笔记十九之相机系统1.运行1.1.游戏相机1.2.轨迹球相机 2.游戏相机与轨迹球相机切换3.博主笔记本要运行需要更改的文件更改1:28_OpenGL_CameraSystem/applicat…

设计模式-生成器模式/建造者模式Builder

构建起模式&#xff1a;将一个复杂类的表示与其构造分离&#xff0c;使得相同的构建过程能够得出不同的表示。&#xff08;建造者其实和工厂模式差不多&#xff09; 详细的UML类图 图文说明&#xff1a;距离相同的构建过程 得出不同的展示。此时就用两个类&#xff08;文本生成…