项目心得八

toast组件loading的使用

      this.$toast.loading({
        message: "修改中...",
        forbidClick: true,
        duration: 0,
      });
-----------------------------------
 this.$toast.success("修改成功!");

封装组件

<template>
  <div class="updateGender">
    <!-- @confirm="onConfirm"
      @cancel="onCancel"
      @change="onChange" -->
    <van-picker title="标题" show-toolbar :columns="columns"
    :default-index="value" @cancel="$emit('close')" @change="onChange"
    @confirm="onComfirm"/>
  </div>
</template>

<script>
import { updateUserProfile } from "@/api/user";
export default {
  name: "updateGender",
  components: {},
  props: {
    value: {
      type: Number,
      required: true,
      localGender: 0,
    },
  },
  data() {
    return {
      columns: ["男", "女"],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onChange(picker, value, index) {
      this.localGender = index;
    },
    async onComfirm() {
      const localGender = this.localGender;
      this.$toast.loading({
        message: "修改中...",
        forbidClick: true,
        duration: 0,
      });
      try {
        await updateUserProfile({
          gender: localGender,
        });
        // 更新视图
        this.$emit("input", localGender);
        // 关闭弹层
        this.$emit("close");
        this.$toast.success("修改成功!");
      } catch (error) {
        this.$toast("修改失败!");
      }
    },
  },
};
</script>
<style lang="less" scoped></style>

上传图片文件预览操作

 <input type="file" hidden ref="file" @change="onChangeFile">
-----------------------------------------------------------------
    onChangeFile() {
        const file = this.$refs.file.files[0]
        // 转化blob地址
        this.img = window.URL.createObjectURL(file)
        this.isUpdatePhotoShow = true
        // 解决选择相同图片,不触发change
        this.$refs.file.value = ""
    }

发送请求字段

Content-Type:application/json ===> 普通js对象
Content-Type:multipart/form-data === :formData = new FormData()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值