小黑记事本(组件版)

黑马的课程案例:小黑记事本组件版

拆分基础组件、渲染待办功能、添加任务、删除任务、   底部合计和清空功能、持久化存储

这是一些代码的注释和解释

这是完整代码,可以直接复制使用

App.vue

<template>
  <!-- 主体区域 -->
  <section id="app">
    <!-- 注册事件、监听子组件  -->
    <TodoHeader @add="handleAdd"></TodoHeader>
    <TodoMain :list="list" @del="handelDel"></TodoMain>
    <TodoFooter :list="list" @clear="clear"></TodoFooter>
  </section>
</template>

<script>
import TodoHeader from './components/TodoHeader.vue'
import TodoMain from './components/TodoMain.vue'
import TodoFooter from './components/TodoFooter.vue'

export default {
  data() {
    return {
      //实现持久化存储
      list: JSON.parse(localStorage.getItem('list')) || [
        { id: 1, name: '打篮球' },
        { id: 2, name: '看电影' },
        { id: 3, name: '逛街' },
      ],
    }
  },
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter,
  },
  //6.持久化存储
  watch: {
    list: {
      deep: true,
      handler(newVal) {
        localStorage.setItem('list', JSON.stringify(newVal))
      },
    },
  },
  methods: {
    //添加---用时间戳添加
    handleAdd(todoName) {
      // console.log(todoName)
      this.list.unshift({
        id: +new Date(),
        name: todoName,
      })
    },
    //删除---过滤id
    handelDel(id) {
      // console.log(id);
      this.list = this.list.filter((item) => item.id !== id)
    },
    //清空---让数组为空
    clear() {
      this.list = []
    },
  },
}
</script>

<style>
</style>

TodoHeader.vue

<template>
   <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input placeholder="请输入任务" class="new-todo" 
    v-model="todoName" @keyup.enter="handleAdd"/>
    <!-- v-model获取输入框的值-->
    <button class="add" @click="handleAdd">添加任务</button>
    <!-- 给按钮注册点击事件-->
  </header>
</template>

<script>
export default {
  data(){
    return {
      todoName:''   //由v-model绑定输入获取,默认为空
    }
  },
  methods:{
    //添加
    handleAdd(){
      // console.log(this.todoName)        //打印得到的todoName
      this.$emit('add',this.todoName)      //传递添加事件
      this.todoName = ''                   //添加完成之后清空输入框
    }
  }
}
</script>

<style>

</style>

TodoMain.vue

<template>
  <!-- 列表区域 -->
  <section class="main">
    <ul class="todo-list">
      <!-- v-for渲染数据,:key必写 -->
      <li class="todo" v-for="(item, index) in list" :key="item.id">
        <div class="view">
          <!--  渲染数据 -->
          <span class="index">{{ index + 1 }}.</span>
          <label>{{ item.name }}</label>
          <!-- 注册删除事件  -->
          <button class="destroy" @click="handleDel(item.id)"></button>
        </div>
      </li>
    </ul>
  </section>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
    },
  },
  methods: {
    handleDel(id) {
      this.$emit('del', id)    //传递删除参数id
    },
  },
}
</script>

<style>
</style>

TodoFooter.vue

<template>
  <!-- 统计和清空 -->
  <footer class="footer">
    <!-- 统计 -->
    <span class="todo-count"
      >合 计:<strong> {{ list.length }} </strong></span
    >
    <!-- 注册清空事件 -->
    <button class="clear-completed" @click="clear">清空任务</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
    },
  },
  methods:{
    clear(){
      this.$emit('clear')    //传递清空请求
    }
  }
}
</script>

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
小黑记事本是一款简单好用的记事本软件。软件不仅拥有Windows自带记事本的所有功能,还具有自定义文本底纹,文字编辑页面缩放,半透明模式等诸多功能。软件界面美观简洁、简单全面、实用方便,可快速上手,轻轻松松完成日常记事本功能,真正做到简单全面实用。是用户实现记事本功能的好帮手。 小黑记事本功能 1、自定义语法高亮,支持众多脚本文件。 2、支持ANSI,Unicode,UTF-8等编码互换 3、可自定义文本底纹,让你的文本多姿多彩 4、支持文字编辑页面的缩放,并提供缩放滑块 5、可对任意的文本块进行操作 6、可自定义代码页和字符集,对中文支持良好 7、使用标准的正则表达式搜索和替换 8、独有的半透明模式,让你的文本编辑更为方便 9、完美支持中文,并自带多种字体,可随意更换文本内的字体 10、贴心一对一客服,实时跟进软件用户体验 小黑记事本的安装 把下载好的安装包解压到当前文件夹,之后双击【HNInstall_Setup.exe】运行文件进行安装,打开的时候会出现安装框,依次开始安装,依照步骤点击下一步,并选择同意协议和软件安装位置即可。 点击【完成】按钮,小黑记事本软件安装过程就完成了。 小黑记事本的使用 安装完成后,点击【小黑记事本】快捷方式即可进入小黑记事本软件。如图所示,这是软件的主界面。软件安装运行之后,用户可以点击界面的各种按钮实现自己所需要的各种功能。 如图所示,这是软件的更换底纹功能。软件的功能就大致介绍到这里了,软件其余的具体功能就有小伙伴们自己去发掘吧。 小黑记事本的卸载 依次选择开始-> 所有程序 ->小黑记事本软件->卸载小黑记事本软件。 或者依次打开我的电脑->卸载或更改程序->卸载你所卸载的软件,您可以用 Window XP控制面板中的添加或删除程序功能,或用 Windows Vista、Windows 7中的程序和功能删除小黑记事本软件, 然后点击开始卸载,按步骤依次点击下一步,直至完成。
小黑记事本是一个使用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、付费专栏及课程。

余额充值