• todolist案列——vue脚手架(完整版)


    目录

    一、项目目录

    二、各组件

    1.  父组件App.vue

    2.  components文件夹下得子组件 

    2.1:  Header.vue

    2.2:  List.vue

    2.3:  Footer.vue

    2.4:  Item.vue

    三、整体效果实现


    一、项目目录

    二、各组件

    1.  父组件App.vue

    1. <script>
    2. import Header from "./components/Header.vue";
    3. import List from "./components/List.vue";
    4. import Footer from "./components/Footer.vue";
    5. export default {
    6. name: 'App',
    7. data(){
    8. return {
    9. todo:[
    10. {id:1,name:'Vue',done:false},
    11. {id:2,name:'React',done:false},
    12. {id:3,name:'Java',done:true},
    13. {id:4,name:'HTML+CSS',done:true},
    14. ]
    15. }
    16. },
    17. methods:{
    18. addTodo(name){
    19. const item={id:new Date().getTime(),name,done:false};
    20. this.todo.unshift(item);
    21. console.log('app',item);
    22. },
    23. delTodo(id){
    24. this.todo=this.todo.filter((item)=>{
    25. return item.id!=id;
    26. })
    27. },
    28. //修改状态
    29. editDone(id){
    30. this.todo.forEach((item)=>{
    31. if(item.id==id){
    32. item.done = !item.done;
    33. }
    34. })
    35. },
    36. //全选/全不选
    37. editAll(checked){
    38. this.todo.forEach((item)=>{
    39. item.done=checked;
    40. })
    41. },
    42. //清除所有已完成任务
    43. delAll(){
    44. this.todo=this.todo.filter((item)=>{
    45. return item.done!=true;
    46. })
    47. }
    48. },
    49. components:{
    50. Header,
    51. List,
    52. Footer
    53. },
    54. }
    55. script>
    56. <style>
    57. *{
    58. margin: 0px;
    59. padding: 0px;
    60. }
    61. li{
    62. list-style: none;
    63. }
    64. .main{
    65. width: 600px;
    66. margin: auto;
    67. }
    68. .btn{
    69. position: absolute;
    70. right: 0px;
    71. background: red;
    72. color: #fff;
    73. width: 90px;
    74. height: 33px;
    75. border: none;
    76. border-radius: 5px;
    77. cursor: pointer;
    78. display:none;
    79. }
    80. style>

    2.  components文件夹下得子组件 

    2.1:  Header.vue

    1. <script>
    2. export default{
    3. name:'Header',
    4. props:['addTodo'],
    5. methods:{
    6. pressAdd(e){
    7. this.addTodo(e.target.value);
    8. console.log('111');
    9. }
    10. },
    11. }
    12. script>
    13. <style >
    14. /* 头部文件 */
    15. .header{
    16. border: 1px solid #999999;
    17. padding: 15px;
    18. }
    19. .header input{
    20. width: 100%;
    21. height: 40px;
    22. line-height: 40px;
    23. }
    24. style>

    2.2:  List.vue

    1. <script>
    2. import Item from '../components/Item'
    3. export default{
    4. name:'List',
    5. props:['todo','delTodo','editDone'],
    6. //测试是否拿到了todo数组的值
    7. mounted(){
    8. //console.log(this.todo);
    9. },
    10. components:{
    11. Item,
    12. },
    13. }
    14. script>
    15. <style>
    16. /* list样式 */
    17. .list{
    18. border: 1px solid #999999;
    19. padding: 15px;
    20. margin-top: 15px;
    21. }
    22. .list li{
    23. height: 40px;line-height: 40px;color: #666;
    24. border-bottom: 1px solid #999999;
    25. position: relative;
    26. }
    27. .list li .btn{
    28. top:2px;
    29. }
    30. .list li:hover .btn{
    31. display: block;
    32. }
    33. style>

    2.3:  Footer.vue

    1. <script>
    2. export default{
    3. name:'Footer',
    4. props:['todo','editAll','delAll'],
    5. computed:{
    6. alldone(){
    7. return this.todo.reduce((total,current)=>{
    8. return total+(current.done?1:0)
    9. },0);
    10. },
    11. alltodo(){
    12. return this.todo.length;
    13. },
    14. checkall(){
    15. return this.alldone!=0 && this.alltodo==this.alldone;
    16. }
    17. },
    18. methods:{
    19. changeAll(e){
    20. this.editAll(e.target.checked);
    21. },
    22. pressDelAll(){
    23. this.delAll();
    24. }
    25. }
    26. }
    27. script>
    28. <style >
    29. /* 底部 */
    30. .footer{
    31. border: 1px solid #999999;
    32. padding: 15px;
    33. margin-top: 15px;
    34. position: relative;
    35. }
    36. .footer .btn{
    37. display: block;
    38. padding: 10px 20px;
    39. width: auto;
    40. height: auto;
    41. padding-bottom: 9px;
    42. top:6px;
    43. right: 5px;
    44. }
    45. style>

    2.4:  Item.vue

    1. <script>
    2. export default {
    3. name:'Item',
    4. props:['item','delTodo','editDone'],
    5. methods:{
    6. pressDel(id){
    7. this.delTodo(id);//调用父组件回调函数 并传递id
    8. }
    9. },
    10. computed:{
    11. changedone:{
    12. get(){
    13. // return true;
    14. return this.item.done;
    15. },
    16. set(done){
    17. console.log(done);
    18. this.editDone(this.item.id);
    19. }
    20. }
    21. }
    22. }
    23. script>
    24. <style scoped>
    25. style>

    三、整体效果实现

     

  • 相关阅读:
    亚马逊暖风机CE认证UL报告办理周期费用
    替换Series中的值replace()函数
    kettle经验篇:MongoDB-delete插件问题
    WebSocket实现聊天功能
    【毕业设计】stm32单片机智能扫地机器人 - 嵌入式 物联网
    S7-200系列西门子plc简介
    AI面试常见题目整理
    LeetCode50天刷题计划(Day 6—— 整数反转 14.20-15.20)
    Collectors.groupingBy()
    城市级智慧停车解决方案白皮书
  • 原文地址:https://blog.csdn.net/qq_53841687/article/details/126505717