发表于: 2020-09-03 20:25:17

1 2466


今天完成的事情:
学习了axios.put请求,和form格式数据转换

  methods: {
    add() {
      this.$router.push({ path: "/add" });
    },
    empty() {
      //清空
      this.title = "";
      this.author = "";
      this.startAt = "";
      this.endAt = "";
      this.type = "";
      this.status = "";
    },
    search() {
      //手动搜索
      if (this.startAt == "" || this.startAt == null) {
        var startDay = this.startAt;
      } else {
        var start = new Date(this.startAt);
        var startDay = Number(start); //日期格式转换成时间戳
      }
      if (this.endAt == "" || this.endAt == null) {
        var endDay = this.endAt;
      } else {
        var end = new Date(this.endAt);
        var endDay = Number(end);
      }
      axios
        .get("api/a/article/search", {
          params: {
            title: this.title,
            author: this.author,
            startAt: startDay,
            endAt: endDay,
            type: this.type,
            status: this.status,
          },
        })
        .then((res=> {
          this.resdata = res.data.data.articleList//列表数据
          this.restotal = res.data.data.total//总数
          console.log(res);
          this.$notify({
            title: "操作成功",
            type: "success",
            position: "bottom-right",
          });
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      //分页
      if (this.startAt == "" || this.startAt == null) {
        var startDay = this.startAt;
      } else {
        var start = new Date(this.startAt);
        var startDay = Number(start); //日期格式转换成时间戳
      }
      if (this.endAt == "" || this.endAt == null) {
        var endDay = this.endAt;
      } else {
        var end = new Date(this.endAt);
        var endDay = Number(end);
      }
      axios
        .get("api/a/article/search", {
          params: {
            title: this.title,
            author: this.author,
            startAt: startDay,
            endAt: endDay,
            type: this.type,
            status: this.status,
            page: val,
          },
        })
        .then((res=> {
          this.resdata = res.data.data.articleList//列表数据
          this.restotal = res.data.data.total//总数
        });
    },
    out() {
      //删除列表数据
      this.$confirm(
        "删除后该Articler图将直接下架并在本地删除,你确定要执行删除操作吗?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    state(item) {
      //上线/下线操作
      var itemid = item.id;
      if (item.status == "1") {
        var itemstatus = "2";
      } else {
        itemstatus = "1";
      }
      var idqs = { id: itemidstatus: itemstatus };
      axios.put(`api/a/u/article/status`qs.stringify(idqs)).then((res=> {
        //重新渲染数据
        this.search();
      });
    },
  },


明天计划的事情:

继续完成任务6-10


返回列表 返回列表
评论

    分享到