时间:2021-05-26
CSS
.upload-btn-box { margin-bottom: 10px; button { margin-right: 10px; } input[type=file] { display: none; }}HTML
<div class="upload-btn-box"> <Button @click="choiceImg" icon="ios-cloud-upload-outline" type="primary">点击上传</Button> <input ref="filElem" type="file" class="upload-file" @change="getFile"></div>Script
choiceImg(){ this.$refs.filElem.dispatchEvent(new MouseEvent('click')) },getFile(){ var that = this; const inputFile = this.$refs.filElem.files[0]; if(inputFile){ if(inputFile.type !== 'image/jpeg' && inputFile.type !== 'image/png' && inputFile.type !== 'image/gif'){ alert('不是有效的图片文件!'); return; } this.imgInfo = Object.assign({}, this.imgInfo, { name: inputFile.name, size: inputFile.size, lastModifiedDate: inputFile.lastModifiedDate.toLocaleString() }) const reader = new FileReader(); reader.readAsDataURL(inputFile); reader.onload = function (e) { that.imgSrc = this.result; } } else { return; } }补充知识: vue下打包时几个文件选择文件打包一起 并做懒加载
直接上代码
const DeviceManage = r => require.ensure([], () => r(require(deviceManagePath + 'main/DeviceManage')), 'g-DeviceManage');const SingleDeviceSet = r => require.ensure([], () => r(require(deviceManagePath + 'deviceSet/SingleDeviceSet')), 'g-DeviceManage');const ModifyNo = r => require.ensure([], () => r(require(deviceManagePath + 'modifyNo/ModifyNo')), 'g-DeviceManage');const PricePerTime = r => require.ensure([], () => r(require(deviceManagePath + 'pricePerTime/PricePerTime')), 'g-DeviceManage');const SetParams = r => require.ensure([], () => r(require(deviceManagePath + 'setParams/SetParams')), 'g-DeviceManage');const ShowDevicePrice = r => require.ensure([], () => r(require(deviceManagePath + 'showDevicePrice/ShowDevicePrice')), 'g-DeviceManage');const parameterSetting = r => require.ensure([], () => r(require(deviceManagePath + 'parameterSetting/parameterSetting')), 'g-DeviceManage');const SetParams3G = r => require.ensure([], () => r(require(deviceManagePath + 'setParams3G/SetParams3G')), 'g-Device3Gparams');这么写 所有g-DeviceManage的文件会被打包在一起
以上这篇Vue触发input选取文件点击事件操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
复制代码代码如下:请选择文件//点击#selectFile触发input:file的click事件复制代码代码如下:jQuery('#selectFile').
=在angular项目中时常有一些click、input、focusout等事件操作,那么如何在单元测试中触发这些事件呢?一、触发Click事件//方法一con
函数防抖定义:多次触发事件后,事件处理函数只执行一次,并且是在触发操作结束时执行。在vue中对click添加防抖处理conston=Vue.prototype.
代码如下:复制代码代码如下:jquery点击复选框触发事件给input赋值-柯乐义*{margin:0;padding:0;list-style-type:no
主要通过input输入事件配合css的transform动态改变实现这种效果。实际调试过程中,input组件bindinput事件触发后回调的detail对象,