关于H5 图片上传(全篇)

关于H5 图片上传(全篇),第1张

首先在main.js引入 import { Form,Field } from ‘vant’;

Vue.use(Form);
Vue.use(Field);

vue文件 template 写入
        
          
        
vue文件 js 写入

  data() {
    return {
      files: [], //图片
      imgList: [],
    };
  },
  
 methods: {
    // 图片信息
    toChooseImg(file) {
      let localData = file.content;
      this.uploadImg(localData.split(",")[1]);
    },
    // 上传图片到服务器
    uploadImg(img) {
      this.$http
        .postRequest("/frontEnd/F/F001", {
          file_type: "1",
          attach_type: "photo",
          file_ext: "jpeg",
          image: img,
          toAliyun: "1",
        })
        .then((res) => {
          if (res.result != "0") {
            this.$toast.fail(res.msg);
          } else {
            this.files.push(res.filePath);
          }
        });
    },
    // 删除图片
    delPic(idx) {
      this.imgList.splice(idx, 1);
      this.files.splice(idx - 1, 1);
    },
    },

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存