栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

vue小案例---todolist

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vue小案例---todolist

效果图:

        

首先我们在vuex中先请求数据:
import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
  },
  mutations: {
    setlist(state, data) {
      data.map((item) => {
        item.zt = false;
      });
      state.list = data;
    },
    setZt(state, data) {
      state.list.map((item) => {
        if (item.id == data) {
          item.zt = !item.zt;
        }
      });
    },
    setAdd(state,data){
      state.list.unshift({body:data,zt:false,id:Date.now()})
    }
  },
  actions: {
    async setData(commit, limit = 10) {
      var res = await axios.get(
        "http://jsonplaceholder.typicode.com/posts?_limit=" + limit
      );
      console.log(res.data);
      this.commit("setlist", res.data);
    },
  },
  modules: {},
});
然后在另一个vue文件中写样式以及逻辑操作:



.total {
  width: 1300px;
  min-height: 400px;
  margin: 0 auto;
  .inp {
    width: 90%;
    height: 50px;
    background: red;
    margin: 0 auto;
    display: flex;
    input {
      height: 100%;
      border: 0px;
      outline: 0px;
      padding-left: 10px;
      flex-grow: 1;
    }
    button {
      width: 100px;
      height: 100%;
      margin: 0px;
    }
  }
  .sel {
    width: 90%;
    height: 50px;
    margin: 10px auto;
    .sx {
      display: flex;
      justify-content: space-around;
      .no::before {
        content: "";
        display: inline-block;
        width: 10px;
        height: 10px;
        background-color: darkred;
        margin-right: 4px;
      }
      .yes::before {
        content: "";
        display: inline-block;
        width: 10px;
        height: 10px;
        background-color: red;
        margin-right: 4px;
      }
      div {
        vertical-align: middle;
        cursor: pointer;
      }
    }
  }
  .list {
    width: 90%;
    min-height: 100px;
    // background: red;
    margin: 10px auto;
    display: flex;
    flex-wrap: wrap;
    gap: 5%;

    .lists {
      width: 30%;
      min-height: 60px;
      border-radius: 5px;
      background: darkred;
      padding: 10px;
      box-sizing: border-box;
      margin:10px 0;
      color: #fff;
      overflow: hidden;
    }
    .active {
      background: red;
    }
  }
}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/293744.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号