Vue.component('my-wx-upload', {
template: `
<mu-grid-list :cols="3" :cellHeight="90">
<mu-grid-tile titleBarClass v-for="img, index in readyUploadImages" :key="index">
<img :src="img" @click="preview(img)"/>
<div slot="action">
<i @click="remove(index)" class="iconfont icondelete" style="color: white;font-size: 2em;"></i>
</div>
</mu-grid-tile>
<mu-grid-tile v-show="uploadIsFull" hideTitleBarClass>
<img @click="add" imgAdd
src="/assets/public/wx/cms/img/add.jpg"/>
</mu-grid-tile>
</mu-grid-list>
`,
props: {
imgList: {type: Array},
chooseImage: {type: Number, default: 9},
},
data() {
return {
readyUploadImages: []
}
},
mounted() {
this.readyUploadImages = this.imgList
},
methods: {
remove(index) {
this.readyUploadImages.splice(index, 1)
},
add() {
wx.chooseImage({
count: this.oddchooseImageCount, // 最多可以选择的图片张数,默认9
sizeType: ['original'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: res => {
this.readyUploadImages = this.readyUploadImages.concat(res.localIds);
// myUpImageBlock
},
fail: function () {
// fail
},
complete: function () {
// complete
}
})
},
preview(img) {
wx.previewImage({
current: img, // 当前显示图片的http链接
urls: this.readyUploadImages // 需要预览的图片http链接列表
});
}
},
computed: {
oddchooseImageCount() {
return this.chooseImage - this.readyUploadImages.length;
},
uploadIsFull() {
return this.readyUploadImages.length !== this.chooseImage
}
},
watch: {
readyUploadImages(val) {
this.$emit('update:imgList', val)
}
}
});

调用方法

<my-wx-upload :img-list.sync="传入一个数组"></my-wx-upload>

上传方法

WxUploadImage(imgList) {
return new Promise((resolve, reject) => {
if (imgList && imgList instanceof Array && imgList.length > 0) {
let promiseList = [];
for (let i = 0; i < imgList.length; i++) {
promiseList[i] = new Promise((resolve, reject) => {
wx.uploadImage({
localId: imgList[i],
success: res => {
resolve(res.serverId);
},
fail: error => {
reject(error);
}
})
});
}
Promise.all(promiseList)
.then(result => {
resolve(result);
})
.then(error => {
reject(error);
})
} else {
reject('传参有误,请传数组格式');
}
})
}

  调用方法

 this.WxUploadImage(this.imageList).then(res => {

                });

基于 muse-ui 封装一个微信公众号上传插件 实现多图上传的更多相关文章

  1. 在微信框架模块中,基于Vue&Element前端的微信公众号和企业微信的用户绑定

    在一个和微信相关的业务管理系统,我们有时候需要和用户的微信账号信息进行绑定,如对公众号.企业微信等账号绑定特定的系统用户,可以进行扫码登录.微信信息发送等操作,用户的绑定主要就是记录公众号用户的ope ...

  2. 从Python爬虫到SAE云和微信公众号:二、新浪SAE上搭建微信服务

    目的:用PHP在SAE上搭建一个微信公众号的服务器. 1.申请一个SAE云账号 SAE申请地址:http://sae.sina.com.cn/  可以使用微博账号登陆,SAE是新浪的云服务,时间也比较 ...

  3. 基于IdentityServer的系统对接微信公众号

    业务需求 公司有两个业务系统,A和B,AB用户之间属于多对一的关系,数据库里面也就是两张表,A表有个外键指向B.现在需要实现以下几个功能. A用户扫描B的二维码,填写相关的注册信息,注册完成之后自动属 ...

  4. 用iframe嵌入了一个微信公众号平台文章的URL

    JS: $.ajaxPrefilter( function (options) { if (options.crossDomain && jQuery.support.cors) { ...

  5. 用laravel搭一个微信公众号后台

    我使用的是laravel5.2, 早期版本可能不适合下面的方法. 在routes.php写下接收微信服务器post请求的路径: Route::post('wechatmp', 'WechatContr ...

  6. PHP 微信公众号真正正确的客服头像上传

    首先我们来看官方文档 这TM的搞笑呢 什么破玩意儿! 需要条件 1 需要有一个客服的账号 (废话) 2 一致jpg格式的图片(扯蛋) 完整流程 1 获取access_token 2获取账号 3 $ur ...

  7. 5-网页,网站,微信公众号基础入门(配置网站--PHP配置上数据库)

    https://www.cnblogs.com/yangfengwu/p/11037653.html php和数据库打交道,这样整个网页就完美了,有了数据存储,交互,动态网页才完美 首先修改下php. ...

  8. 使用NW.js封装微信公众号菜单编辑器为桌面应用

    开发微信公众号的朋友都会遇到一个常见的需求就是修改自定义菜单,如果每个人都去开发这个不经常使用的功能确实有点浪费时间.前段时间在github上找到一个仿企业号的菜单编辑界面,结合微信的C# SDK开发 ...

  9. ABP入门系列(15)——创建微信公众号模块

    ABP入门系列目录--学习Abp框架之实操演练 源码路径:Github-LearningMpaAbp 1. 引言 现在的互联网已不在仅仅局限于网页应用,IOS.Android.平板.智能家居等平台正如 ...

随机推荐

  1. F. Relatively Prime Powers (求([2,n],内不是次方的数量)

    题目:经过提炼后, 题目的意思就是问[2,n] 内,不是次方数的数量 ,: 思路: 答案就是 原理是利用容斥,注意n开i次根是向下取整(这题巨卡精度) 这是大神的思路 ,, 我还没有理解, 先放着,等 ...

  2. object.wait为什么要和synchronized一块使用

    Object.wait 中JDK提供的doc文档 Causes the current thread to wait until another thread invokes the notify() ...

  3. 解决 This application requires Java Runtime Environment XX

    已经安装了 jdk ,并且设置好了 java 环境变量,CMD 运行 java 或 javac 都正常,其他依赖 jdk 的应用程序都能正常运行.但是在运行 jd-gui 1.1.0 的时候,出现错误 ...

  4. eclipse ctrl+h

    之前我的eclipse使用ctrl + h 出现的总是Plug-in Search ,总是需要点那个小三角才能找到File Search ,深感使用不便, 修改方法:Window->Genera ...

  5. git commit之后撤销

    先git log 查看日志,找到需要回退的那次commit的哈希值 然后git reset --soft commit_id ok

  6. Sorted Subsegments

    https://www.hackerrank.com/contests/101hack38/challenges/sorted-subsegments/problem 首先要注意到可以二分答案,比如当 ...

  7. javaweb项目导入myecplise出错

    项目导入出错:移动项目的时候.classpath .project不要删 build path -> use for source floder 把某一文件夹当作源码文件夹 bulid path ...

  8. NewStar 信息分发系统设计

    目录 NewStar 信息分发系统设计 我想要怎么做 系统流程图 解释和初步的模板展示 NewStar 信息分发系统设计 我们在全世界发布网站本质就是向全世界分发我们的信息给客户/潜在客户,然后希望促 ...

  9. Javascript 执行上下文 context&scope

    执行上下文(Execution context) 执行上下文可以认为是 代码的执行环境. 1 当代码被载入的时候,js解释器 创建一个 全局的执行上下文. 2 当执行函数时,会创建一个 函数的执行上下 ...

  10. DataBinding初探 数据绑定的用法 ,import 集合类型,绑定的表达式,访问集合类型2

    数据绑定的用法 import语法   <data> <import type="android.view.view"/> </data>   如 ...