MUI APP中实现图片上传

MUI APP中实现图片上传_第1张图片

  1. 前端页面编写
    <div class="mui-input-row">
    	<label>上传图片label>
    	<div class="mui-button-row">
    		<button type="button" id="gallery" class="mui-btn mui-btn-primary" onclick="return false;" style="float: left;width: 90px;">点击上传button>  
    	div>
    div>
    
  2. js编写
    var displayPhoto = document.getElementById("displayPhoto");
    var galleryBtn = document.getElementById("gallery");
    galleryBtn.addEventListener("tap", function() {
    	plus.gallery.pick(
    		/*执行成功*/
    		function(path) {
    			/*多选图片*/
    			/*var img = "";
    			for(var i in path.files) {
    				img += "";
    			}
    			displayPhoto.innerHTML = img;*/
    			/*单选图片*/
    			var img = "+ path + ">";
    			displayPhoto.innerHTML = img;
    		},
    		/*执行失败*/
    		function(e) {
    			displayPhoto.innerHTML = "读取出错,请重试"
    		}, {
    			filter: "image",
    			/*多选图片 开启后第一个方法的path就变为对象数组 */
    			/*multiple:true*/
    		}
    	)
    })
    

本篇上传至后端,后续会上传后端

你可能感兴趣的:(MUI,前端)