小黑记事本(网页)

小黑记事本(网页),第1张

项目要求

学习背景:学习vue,回顾html和css

代码结构

主体区域:

  
  <section id="todoapp">
    
    <header class="header">
      <h1>小黑记事本h1>
      <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务"
        class="new-todo" />
    header>
    
    <section class="main">
      <ul class="todo-list">
        <li class="todo" v-for="(item,index) in list">
          <div class="view">
            <span class="index">{{ index+1 }}.span>
            <label>{{ item }}label>
            <button class="destroy" @click="remove(index)">button>
          div>
        li>
      ul>
    section>

脚部统计和清除按钮 以及 底部logo图:

    
    <footer class="footer" >
      <span class="todo-count">
        <strong>{{list.length}}strong> items left
      span>
      <button class="clear-completed">
        Clear
      button>
    footer>
  section>
   
  <footer class="info">
    <p>
      <a href="http://www.itheima.com/"><img src="./img/black.png" alt="" />a>
    p>
  footer>

JS部分(vue):

  <script>
    var app = new Vue({
      el: "#todoapp",
      data: {
        list: ["写代码", "吃饭饭", "睡觉觉"],
        inputValue: "好好学习,天天向上"
      },
      methods: {
        add: function () {
          this.list.push(this.inputValue);
        },
        remove:function(index){
          this.list.splice(index,1);
        }
      },
    })
  script>
知识点学习 css
body {
  //最小和最大宽度
  min-width: 230px;
  max-width: 550px;
  //抗锯齿渲染
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
Vue v-for循环的使用
      <ul>
        <li v-for="(item,index) in list">
          <div>
            <span>{{ index+1 }}.</span>
            <label>{{ item }}</label>
            <button @click="remove(index)"></button>
          </div>
        </li>
      </ul>
v-model双向绑定
<!-- v-model双向绑定(学习重点),keyup表示松开键盘时触发, -->
<input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务"
class="new-todo"/>
splice的用法
// splice可以用来删除/添加数组元素
// splice(index,n,"ab","cd")删除从index开始后面的n个元素,
//并从索引处添加"ab""cd"两个字符串。
this.list.splice(index,1)
注意事项

Vue创建对象时,Vue的首字母 V 要大写;
写函数是要注意参数的传递。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1324928.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-12
下一篇2022-06-12

发表评论

登录后才能评论

评论列表(0条)

    保存