vue使用vueCropper裁剪功能,代码复制直接使用
//先安装包
npm install vue-cropper --save-dev
<template>
<div id="merchantInformation">
<div class="upData">
<label class="btn btn-orange" for="uploads">上传LOGO</label>
<input type="file" id="uploads" :value="imgFile" style="position:absolute; clip:rect(0 0 0 0);" accept="image/png, image/jpeg, image/gif, image/jpg" @change="uploadImgg($event, 1)">
<div class="line" >
<div class="cropper-content" >
<div class="cropper">
<vueCropper
ref="cropper"
:img="option.img"
:outputSize="option.size"
:outputType="option.outputType"
:info="true"
:full="option.full"
:canMove="option.canMove"
:canMoveBox="option.canMoveBox"
:original="option.original"
:autoCrop="option.autoCrop"
:autoCropWidth="option.autoCropWidth"
:autoCropHeight="option.autoCropHeight"
:fixedBox="option.fixedBox"
@realTime="realTime"
@imgLoad="imgLoad"
></vueCropper>
</div>
<div style="margin-left:20px;">
<div class="show-preview" :style="{'width': '150px', 'height':'155px', 'overflow': 'hidden', 'margin': '5px'}">
<div :style="previews.div" class="preview">
<img :src="previews.url" :style="previews.img">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template> <script>
import { VueCropper } from 'vue-cropper'
export default {
data(){
return{
crap: false,
previews: {},
option: {
img: '',
outputSize:1, //剪切后的图片质量(0.1-1)
full: false,//输出原图比例截图 props名full
outputType:'png',
canMove: true,
original: false,
canMoveBox: true,
autoCrop: true,
autoCropWidth: 132,
autoCropHeight: 132,
fixedBox: true,
fixedNumber: [1,1]
},
fileName:'', //本机文件地址
imgFile:'',
imgurl:''
}
},
components: {
VueCropper
},
methods:{
AddImg(){
this.$refs.cropper.getCropBlob( data => { //把裁剪后的数据上传给后台
console.log(data)
})
},
// 实时预览函数
realTime(data) {
this.previews = data
console.log(this.previews)
},
//选择本地图片
uploadImgg(e, num) {
console.log('uploadImg');
var _this = this;
//上传图片
var file = e.target.files[0];
_this.fileName = file.name;
if (!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)) {
this.$message({
message: '图片类型必须是.gif,jpeg,jpg,png,bmp中的一种',
type: 'warning'
});
return false
}
var reader = new FileReader();
reader.onload =(e) => {
let data;
if (typeof e.target.result === 'object') {
// 把Array Buffer转化为blob 如果是base64不需要
data = window.URL.createObjectURL(new Blob([e.target.result]))
}
else {
data = e.target.result
}
if (num === 1) {
_this.option.img = data
} else if (num === 2) {
_this.example2.img = data
}
}
// 转化为base64
// reader.readAsDataURL(file)
// 转化为blob
reader.readAsArrayBuffer(file);
},
imgLoad (msg) {
console.log('imgLoad')
console.log(msg)
}
}
}
</script> <style lang="less">
.input_text .el-cascader .el-input .el-input__inner{width: 477px;height: 40px;border: 1px solid #f1f1f1;}
.input_text .el-select .el-input .el-input__inner{width: 477px;height: 40px;border: 1px solid #f1f1f1;}
#merchantInformation .upload-demo{display: flex;}
#merchantInformation .upload-demo li{width: 100px;height: 113px;margin-top: 0px;display: inline-block;}
#merchantInformation .el-date-editor.el-input, .el-date-editor .el-input__inner{width: 477px;height: 40px;}
#merchantInformation .upload-demo .el-upload-list{display: none;}
</style> <style lang="less" scoped>
#merchantInformation{
height: 925px;width:890px;box-shadow: 0px 0px 1px #dfdddd;background:#fff;overflow: hidden;
}
.uploadingLogo{margin-right: 80px;}
// .uploadingLogoa{margin-right: 70px;}
.logoUrl{max-width: 300px;border-radius: 10px;}
.propagandaUrl{width: 265px;height: 177px;}
.amendd{position: absolute;right: 90px;top: 12px;cursor: pointer;display: flex;align-items: center;color: #1c8cfa;}
.uploadImga{width: 100px;height: 90px;margin-top: 10px;} .perfect{color: #1c8cfa;font-size: 14px;display: flex;justify-content: center;flex-wrap:wrap;
p{cursor: pointer;width: 100%;text-align: center;margin-top: 10px;}
}
.logo_I{width: 100px;height: 100px;}
.UploadPictures_IMG{width: 120px;height: 100px;margin-left: 20px;}
.hintsize{font-size: 12px;color: #343435;}
.info {
width: 720px;
margin: 0 auto;
.oper-dv {
height:20px;
text-align:right;
margin-right:100px;
a {
font-weight: 500;
&:last-child {
margin-left: 30px;
}
}
}
.info-item {
margin-top: 15px;
label {
display: inline-block;
width: 100px;
text-align: right;
}
.sel-img-dv {
position: relative;
.sel-file {
position: absolute;
width: 90px;
height: 30px;
opacity: 0;
cursor: pointer;
z-index: 2;
}
.sel-btn {
position: absolute;
cursor: pointer;
z-index: 1;
}
}
}
} .cropper-content{
display: flex;
.cropper{
width: 200px;
height: 200px;
}
.show-preview{
width: 132px !important;height: 135px !important;
flex: 1;
-webkit-flex: 1;
display: flex; .preview{
overflow: hidden;
border-radius: 20px;
border:1px solid #cccccc;
background: #cccccc;
margin-left: 40px;
}
}
}
.cropper-content .show-preview .preview {margin-left: 0;}
.btn-orange{width: 100px;height: 40px;display: block;line-height: 40px;background: #1c8cfa;color: #fff;text-align: center;
border-radius: 10px;margin-right: 30px;
}
.upData{display: flex;align-items: center;margin-top: 20px; }
.line{margin-left: 21px;} </style>
vue使用vueCropper裁剪功能,代码复制直接使用的更多相关文章
- 一行代码彻底禁用WordPress缩略图自动裁剪功能
记得在博客分享七牛缩略图教程的时候,提到过 WordPress 默认会将上传的图片裁剪成多个,不但占用磁盘空间,也会拖慢网站性能,相当闹心! 当时也提到了解决办法: ①.关闭主题自带缩略图裁剪功能(若 ...
- vue 图片上传功能
这次做了vue页面的图片上传功能,不带裁剪功能的! 首先是html代码,在input框上添加change事件,如下: <ul class="clearfix"> ...
- vue-cropper裁剪上传
效果图: 全部代码: npm install vue-cropper //首先 安装vue-cropper main.js全局引用: import VueCropper from 'vue-cropp ...
- 用JQuery仿造QQ头像裁剪功能
最近工作真心忙碌,几乎没时间写博客.今天趁周末来仿一个QQ头像裁剪功能插件.效果如下: 所有文件都可在我的Github上下载,从头到尾从简到繁按步骤一共分了9个HTML文件,每个步骤文件里的注释都写的 ...
- ArcGIS API for Silverlight 使用GP服务实现要素裁剪功能
原文:ArcGIS API for Silverlight 使用GP服务实现要素裁剪功能 昨天一QQ好友问了一个关于裁剪的问题,感觉自己也没有帮上什么忙,之后自己做了一个裁剪的例子,不过在做这个例子的 ...
- jQuery插件ImgAreaSelect 实例讲解一(头像上传预览和裁剪功能)
上一节随笔中,我们已经知道了关于jQuery插件ImgAreaSelect基本的知识:那么现在看一下实例: 首先,要知道我们应该实现什么功能? (1)图片能够实现上传预览功能 (2)拖拽裁剪图片,使其 ...
- CI 结合 vue.js 的搜索功能模块
CI 结合 vue.js 的搜索功能模块 最近在有优化公司后台的某个模块的搜索功能优化 原先的是这个样子的,很是单调: 老大给我找个图希望我能弄成这样子: 经过不断修改,最后成了这样子 是不是比以前好 ...
- 20个开发人员非常有用的Java功能代码
本文将为大家介绍20个对开发人员非常有用的Java功能代码.这20段代码,可以成为大家在今后的开发过程中,Java编程手册的重要部分. 1. 把Strings转换成int和把int转换成String ...
- ThinkPHP实现支付宝接口功能 代码实例
我们这里用的是即时到帐的接口,具体实现的步骤如下: [title]一.下载支付宝接口包[/title]下载地址:https://doc.open.alipay.com/doc2/detail?tree ...
随机推荐
- Mc小冰总结的Android开发工程师面试题以及答案,android程序员必备,详解
1.请谈一下Android系统的架构. 答:Android系统采用了分层架构,从高层到低层分别是应用程序层.应用程序框架层.系统运行库层和linux核心层. 2.谈谈android大众常用的五种布局. ...
- cookies、sessionStorage和localStorage
浏览器的缓存机制提供了可以将用户数据存储在客户端上的方式,可以利用cookie,session等跟服务端进行数据交互.浏览器查看方式: HTML4的本地存储 cookie 一.cookie和sess ...
- Webpack 入门指迷
大概算是一份教程吧, 只不过效果肯定不如视频演示之类的好..Webpack 最近在英文社区上经常看到, 留了心, 但进一步了解是通过下边的视频:视频: How Instagram.com Works, ...
- Mysql业务设计(逻辑设计)
逻辑设计 数据库设计三大范式 数据库设计第一大范式 数据库表中所有的字段都只具有单一属性 单一属性的列是由基本数据类型所构成 设计出来的表都是简单的二维表 数据库设计的第二大范式 要求表中只有一个业务 ...
- (高难度SQL)从产品表中找出相同前缀 (都云作者痴 谁解其中味)
--期盼值 找出AA,3;PDST,3;QPL-,3;TP-,2; --基本表 create table tb_product( id number(9,0) primary key, name nv ...
- docker 修改容器配置文件
启动docker镜像命令docker run 可以指定端口映射,但是容器一旦创建就无法在通过命令修改.通常是保存镜像在创建一个新的容器.有没有办法不保存镜像直接修改这个容器呢?答案是有的,本文已mys ...
- python urllib.request
一.简介 urllib.request 模块提供了访问 URL 的相关功能 二.常用函数 urllib.request.urlopen("http://httpbin.org", ...
- Python中的type(),isinstance,()dir(),的区别
1.type() type(),获取一个变量的类型,返回值为:<class '类名'>,属于class类型2.isinstance() isinstance(),判断一个对象是否属于某种数 ...
- Javaweb中的请求路径的相关总结
重定向和转发相对路径和绝对路径问题 注意:转发和重定向的URLString前有加 / 为绝对路径 反之为相对路径 1.假设通过表单请求指定的Url资源 action="LoginServ ...
- python3 变量
python 3变量名不能以数字开头但能数字结尾 变量名大小写敏感 在多个单词组成的变量名中以下划线间隔