国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

前端vue點(diǎn)擊圖片上傳(帶封裝方法)

這篇具有很好參考價(jià)值的文章主要介紹了前端vue點(diǎn)擊圖片上傳(帶封裝方法)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

第一種

直接用,圖片路徑自己換一下

<template>
	<view class="uPImg">
		<view class="Img">上傳照片 :</view>
		<view class="shangchuan">
			<view class="sc2" v-for="(item, index) in imgList" :key="index">
				<image class="del" @click="del(index)" src="../../../static/property/paymentUpload.png" mode="">
				</image>
				<image class="Img3" :src="item" mode=""></image>
			</view>
			<view class="sc2" v-if="imgList.length < 3" @click="upload">
				<image class="sc3" src="../../../static/property/paymentUpload.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			imgList: [],
		},
		methods {
			// 點(diǎn)擊上傳圖片
			upload() {
					uni.chooseImage({
						count: 1, //默認(rèn)9
						sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認(rèn)二者都有
						sourceType: ['album'], //從相冊選擇
						loop: true,
						success: res => {
							console.log(res);
							if (res.tempFilePaths.length != 0) {
								this.imgList.push(res.tempFilePaths[0]);
							}
							console.log(JSON.stringify(res.tempFilePaths));
							var tempFilePaths = res.tempFilePaths;

							console.log(tempFilePaths);
							console.log(tempFilePaths[0]);
							uni.uploadFile({
								url: 'http://douzhuoqianshouba.xieenguoji.com/api/ajax/upload',
								filePath: tempFilePaths[0],
								name: 'file',
								success: uploadFileRes => {
									console.log('上傳圖片', JSON.parse(uploadFileRes.data));
								},
								fail(err) {
									console.log(err);
								}
							});
						}
					});
				},

				// // 刪除圖片
				del(index) {
					this.imgList.splice(index, 1);
					console.log(this.imgList);
				},
		}
	}
</script>

<style>
</style>

第二種封裝方法

封裝組件upload.vue

直接用,圖片路徑自己換一下

<template>
	<view></view>
</template>

<script>
export default {
	data() {
		return {
			/*需要返回的圖片*/
			imageList:[]
		};
	},
	onLoad() {},
	props:['num'],
	mounted() {
		this.chooseImageFunc();
	},
	methods: {
		
		/*打開相機(jī)或者相冊,選擇圖片*/
		chooseImageFunc() {
			let self=this;
			uni.chooseImage({
				count: self.$props.num || 9, //默認(rèn)9
				sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認(rèn)二者都有
				sourceType: ['album', 'camera'], //從相冊選擇
				success: function(res) {
					self.uploadFile(res.tempFilePaths);
				},
				fail:function(res){
					self.$emit('getImgs',null);
				},
				complete:function(res){
					
				}
			});
		},
		
		/*上傳圖片*/
		uploadFile: function(tempList) {
			let self = this;
			let i = 0;
			let img_length=tempList.length;
			let params = {
				token: uni.getStorageSync('token'),
                app_id: self.getAppId()
			};
			uni.showLoading({
			    title: '圖片上傳中'
			});
			tempList.forEach(function(filePath, fileKey) {
				uni.uploadFile({
					url: self.websiteUrl + '/index.php?s=/api/file.upload/image',
					filePath: filePath,
					name: 'iFile',
					formData: params,
					success: function(res) {
						let result = typeof res.data === 'object' ? res.data : JSON.parse(res.data);
						if (result.code === 1) {
							self.imageList.push(result.data);
						}else{
							self.showError(result.msg);
						}
					},
					complete: function() {
						i++;
						if (img_length === i) {
							uni.hideLoading();
							// 所有文件上傳完成
							self.$emit('getImgs',self.imageList);
						}
					}
				});
			});
		}
	}
};
</script>

<style></style>

使用組件

引入上面upload.vue

<template>
	<view class=" payment_right">
		<!-- 	<image src="../../../static/property/paymentUpload.png" mode=""></image>
					<!-- 封裝完整的上傳圖片start -->
		<view class="uploadBox d-s-e">
			<view class="item" v-for="(imgs,img_num) in images" :key="img_num" @click="deleteFunc(imgs)">
				<image :src="imgs.file_path || imgs" mode="aspectFit"></image>
			</view>
			<view class="item d-c-c d-stretch" v-if="images.length<1">
				<!-- 			<view class="upload-btn d-c-c d-c flex-1" @click="openUpload()">
								<image src="../../../static/property/paymentUpload.png"></image>
							</view> -->
				<view class="  flex-1" @click="openUpload()">
					<image width="100px" height="100px" src="../../../static/property/paymentUpload.png">
					</image>
				</view>
			</view>
		</view>
		<Upload v-if="isUpload" @getImgs="getImgsFunc"></Upload>
		<!-- 封裝完整的上傳圖片end -->

	</view>
</template>

<script>
	import Upload from '@/components/upload/upload.vue';
	export default {
		components: {
			Upload,
		},
		data() {
			// 封裝的完整的上傳圖片start
			images: [],
			isUpload: false,
			// 封裝的完整的上傳圖片end
		},
		methods {
			// 封裝的完整的上傳圖片start
			// 上傳微信收款碼 刪除圖片
			deleteFunc(e) {
					this.images.splice(e, 1);
				},
				/*獲取圖片*/
				getImgsFunc(e) {
					let self = this;
					self.isUpload = false;
					if (e && typeof(e) != 'undefined') {
						let this_length = self.images.length,
							upload_length = e.length;
						if (this_length + upload_length < 2) {
							self.images = self.images.concat(e);
						} else {
							let leng = 1 - this_length;
							for (let i = 0; i < leng; i++) {
								self.images.push(e[i]);
							}
						}
					}

					this.pay_image = e[0].file_path
					// console.log(e, '獲取所有圖片');
					console.log(e[0].file_path, '圖片路徑');

				},
				/*上傳*/
				openUpload() {
					this.isUpload = true;
					// console.log('打開');
				},
				// 封裝完整的上傳圖片end
		}
	}
</script>

<style lang="scss" scoped>
	.payment_right {
		// width: 440rpx;
		// height: 220rpx;

		.uploadBox .item {
			width: 220rpx;
			height: 220rpx;
		}
	}
</style>

第三種實(shí)戰(zhàn)

圖片

前端vue點(diǎn)擊圖片上傳(帶封裝方法),vue,html,uniapp知識點(diǎn),前端,vue.js,javascript文章來源地址http://www.zghlxwxcb.cn/news/detail-706937.html

代碼

<template>
	<view class="box">
		<!-- 圖片上傳 -->
		<view class="bindingBox">
			<view class=" payment_rightSSS">
				<view class="shangchuan">
					<view class="sc2" v-for="(item, index) in imgList" :key="index">
						<view @click="del(index)" class="dells">
						</view>
						<img class="shangchuan_img" :src="item" mode="aspectFit"></img>
					</view>
					<view class="sc2 gray6 imgUploads" v-if="imgList.length < 1" @click="getUpload">
						<image src="../../../../static/property/paymentUpload.png">
						</image>
					</view>
				</view>
			</view>
		</view>

		<div class="buttonBox">
			<view class="bindingModifyBtn" @click="getUpload">
				修改
			</view>
			<view class="bindingSubmitBtn" @click="bankSubmit">
				提交
			</view>
		</div>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				imgList: [],
			}
		},
		onShow() {},

		mounted() {},
		onLoad() {},
		methods: {
		// 打開相冊
			getUpload() {
				let self = this;
				uni.chooseImage({
					count: 1, //默認(rèn)9
					sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認(rèn)二者都有
					sourceType: ['album'], //從相冊選擇
					loop: true,
					success: function(res) {
						self.uploadFile(res.tempFilePaths);
						// console.log(res,'路徑啊啊啊啊啊');
					},
				});
			},
			/*上傳圖片 */
			uploadFile: function(tempList) {
				let self = this;
				let i = 0;
				let img_length = tempList.length;
				let params = {
					token: uni.getStorageSync('token'),
					app_id: self.getAppId()
				};
				uni.showLoading({
					title: '圖片上傳中'
				});
				tempList.forEach(function(filePath, fileKey) {
					uni.uploadFile({
						url: self.websiteUrl + '/index.php?s=/api/file.upload/image',
						filePath: filePath,
						name: 'iFile',
						formData: params,
						success: function(res) {
							// let result = typeof res.data === 'object' ? res.data :
							// 	JSON.parse(res.data);
							// if (result.code === 1) {
							// 	self.imgList.push(result.data);
							// } else {
							// 	self.showError(result.msg);
							// }


							console.log(res);

							let list = JSON.parse(res.data);
							let filePath = list.data.file_path;

							// 圖片賦值到里面
							// self.imgList.push(list.data.file_path);


							// uniapp圖片上傳判斷一個(gè)數(shù)組長度空上傳,不為空修改
							if (self.imgList.length == []) {
								self.imgList.push(list.data.file_path);
							} else if (self.imgList.length !== []) {
								self.imgList = [list.data.file_path]
							}


							// console.log(list.data.file_path, '路徑路徑路徑路徑');
							// console.log(self.imgList, 'datadataself.imgList數(shù)據(jù)');
						},
						complete: function() {
							i++;
							if (img_length === i) {
								uni.hideLoading();
								// 所有文件上傳完成
								// self.$emit('getImgs', self.imgList);
								self.imgList
							}
						}
					});
				});
			},
			// // 刪除圖片
			del(index) {
				this.imgList.splice(index, 1);
				uni.removeStorageSync('file_path');
				// console.log(this.imgList);
			},

			// 提交修改調(diào)用接口上傳圖片參數(shù)
			bankSubmit() {

				let self = this;

				if (self.imgList == 0) {
					uni.showToast({
						title: '請上傳微信收款碼',
						duration: 2000,
						icon: 'none'
					});
					return;
				}


				uni.showModal({
					title: '提示',
					content: '您確定提交嗎?',
					success: function(o) {

						if (o.confirm) {
							uni.showLoading({
								title: '正在處理'
							});
							self._post(
								'user.user/bindUserWithdrawData', {
									type: '1',
									// wx_code_pic:self.imgList
									wx_code_pic: self.imgList.join()
								},
								function(res) {
									uni.hideLoading();
									uni.showToast({
										title: '操作成功',
										duration: 2000,
										icon: 'success'
									});
									uni.setStorageSync('file_path', String(self.imgList));
									// 存本地
									// uni.setStorageSync('filePath', String(self.imgList));
								}
							);
						}
					}
				});
			}
		},

	}
</script>

<style lang="scss" scoped>
	.bindingBox {
		// display: flex;
		// flex-direction: column;
		// padding: 0 32rpx;
		// box-sizing: border-box;

		// display: flex;
		// justify-content: space-between;
		// align-items: center;
		// padding: 30rpx 20rpx;
		// box-sizing: border-box;
		// font-size: 30rpx;
		background-color: #FFFFFF;

		.payment_rightSSS {
			// .uploadBox .item {
			// 	width: 220rpx;
			// 	height: 220rpx;
			// }
			display: flex;
			justify-content: center;
			align-items: center;

			.shangchuan {
				width: 300rpx;
				height: 300rpx;

				// border: 1rpx solid red;
				.sc2 {
					position: relative;
					// border: 1rpx solid lightseagreen;

					.shangchuan_img {
						// width: 200rpx;
						width: 300rpx;
						height: 300rpx;
						position: relative;

						// left: 52rpx;
						z-index: 9;
					}

					.dells {
						position: absolute;
						width: 100%;
						height: 100%;
						// border: 1rpx solid red;
						z-index: 10;
					}
				}

				.imgUploads {
					width: 300rpx;
					height: 300rpx;

					img {
						width: 100%;
						height: 100%;
						border: 1rpx solid deeppink;
					}
				}
			}
		}
	}

	.buttonBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 32rpx;
		margin: 100rpx auto;

		.bindingModifyBtn {
			background-color: red;
			width: 160px;
			height: 48px;
			line-height: 48px;
			opacity: 1;
			border-radius: 8px;
			border: none;
			font-size: 14px;
			color: #FFFFFF;
			text-align: center;
		}

		.bindingSubmitBtn {
			background-color: red;
			width: 160px;
			height: 48px;
			line-height: 48px;
			opacity: 1;
			border-radius: 8px;
			border: none;
			font-size: 14px;
			color: #FFFFFF;
			text-align: center;
		}
	}
</style>

到了這里,關(guān)于前端vue點(diǎn)擊圖片上傳(帶封裝方法)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 前端上傳圖片到阿里云(pc端和uniapp小程序)

    前端上傳圖片到阿里云(pc端和uniapp小程序)

    官方文檔JavaScript客戶端簽名直傳 如果前端是原生的html寫的話,就去官網(wǎng)下載示例來看,把文件里面的配置修改成子阿里云的配置就好 客戶端進(jìn)行表單直傳到OSS時(shí),會從瀏覽器向OSS發(fā)送帶有Origin的請求消息。OSS對帶有Origin頭的請求消息會進(jìn)行跨域規(guī)則(CORS)的驗(yàn)證,因此需

    2024年02月06日
    瀏覽(21)
  • Vue+element ui上傳圖片和視頻并回顯,點(diǎn)擊放大查看和播放

    1.上傳圖片 html代碼: js代碼:

    2024年02月16日
    瀏覽(27)
  • vue3+ts - element-plus封裝上傳文件圖片組件

    vue3+ts - element-plus封裝上傳文件圖片組件

    ??近期做到的項(xiàng)目中有涉及到上傳圖片上傳文件的需求,因?yàn)槭莗c管理后臺,用到了element-plus框架,所以我也一起使用element-plus中的上傳圖片上傳圖片功能,并對它進(jìn)行封裝成一個(gè)組件,方便在多個(gè)地方使用。 1、上傳文件、視頻 2、上傳圖片 ??在這里上傳圖片和文件是分

    2024年02月12日
    瀏覽(37)
  • Vue前端壓縮圖片后上傳,拍照上傳最佳實(shí)踐

    Vue前端壓縮圖片后上傳,拍照上傳最佳實(shí)踐

    最近有一個(gè)需求,通過手機(jī)拍照后上傳圖片到服務(wù)器,大家應(yīng)該都知道,現(xiàn)在的手機(jī)像素實(shí)在是太高了,隨便拍一張都是 10M 以上,直接上傳到服務(wù)器一方面是浪費(fèi)存儲空間,另外就是特別浪費(fèi)流量,如果網(wǎng)絡(luò)不好還很慢。所以想尋求一種前端壓縮圖片的方案。 在網(wǎng)上找了很

    2024年02月10日
    瀏覽(28)
  • uniapp 開發(fā)小程序,封裝一個(gè)方法,讓圖片使用線上地址
  • 前端Vue圖片上傳組件支持單個(gè)文件多個(gè)文件上傳 自定義上傳數(shù)量 預(yù)覽刪除圖片 圖片壓縮

    前端Vue圖片上傳組件支持單個(gè)文件多個(gè)文件上傳 自定義上傳數(shù)量 預(yù)覽刪除圖片 圖片壓縮

    前端Vue圖片上傳組件支持單個(gè)文件多個(gè)文件上傳 自定義上傳數(shù)量 預(yù)覽刪除圖片 圖片壓縮, 下載完整代碼請?jiān)L問uni-app插件市場址:https://ext.dcloud.net.cn/plugin?id=13099 效果圖如下: 組件初始化 使用方法 HTML代碼部分

    2024年02月09日
    瀏覽(178)
  • vue+el-upload(封裝華為云OBS上傳文件)前端直傳

    vue+el-upload(封裝華為云OBS上傳文件)前端直傳

    注釋:代碼中###是需要填寫自己東西的 以上代碼為封裝的組件代碼,需要引入父組件后調(diào)用配置 下面圖為組件調(diào)用,注冊跟引入就不用我多說了吧,不會的自行百度 注:華為云前端直接上傳的話會出現(xiàn)跨域報(bào)錯(cuò),把華為云OBS CORS跨域規(guī)則設(shè)置一下 我設(shè)置的規(guī)則全部打開了

    2024年02月05日
    瀏覽(113)
  • uniapp 上傳壓縮圖片 兼容h5和小程序的方法

    項(xiàng)目是用uniapp開發(fā)的,當(dāng)時(shí)只是做App端,后來項(xiàng)目擴(kuò)展到H5端, uniapp框架可以跨平臺所以移動端和H5使用的是一套代碼 上傳頭像的時(shí)候要求圖片的大小在2MB一下,所以要壓縮圖片,App端當(dāng)時(shí)使用的是uni.compressImage(OBJECT)壓縮的(詳情見:https://uniapp.dcloud.net.cn/api/media/image.html#

    2024年04月17日
    瀏覽(15)
  • 前端vue elementUI upload上傳組件封裝&多文件上傳&進(jìn)度條,后端servlet request.getPart()接收文件信息

    前端vue elementUI upload上傳組件封裝&多文件上傳&進(jìn)度條,后端servlet request.getPart()接收文件信息

    選中多個(gè)文件上傳 通過 axios請求 onUploadProgress 方法監(jiān)聽 on-progress on-success 用這兩個(gè)鉤子函數(shù)實(shí)現(xiàn)進(jìn)度條 下面有對應(yīng)的函數(shù)。 本文是每個(gè)文件一個(gè)請求上傳 也可以用一個(gè)請求上傳多個(gè)文件,需要將文件遍歷添加到 form 表單中,后端用 request.getParts(); 獲取集合,有需要的可以改

    2024年02月11日
    瀏覽(33)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包