Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dai-siki/vue-image-crop-upload
A beautiful vue component for image cropping and uploading. (vue图片剪裁上传组件)
https://github.com/dai-siki/vue-image-crop-upload
avatar file-upload image-crop image-uploader vue
Last synced: about 1 month ago
JSON representation
A beautiful vue component for image cropping and uploading. (vue图片剪裁上传组件)
- Host: GitHub
- URL: https://github.com/dai-siki/vue-image-crop-upload
- Owner: dai-siki
- Created: 2016-12-20T08:15:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T15:41:52.000Z (about 2 years ago)
- Last Synced: 2024-11-01T07:35:30.495Z (about 1 month ago)
- Topics: avatar, file-upload, image-crop, image-uploader, vue
- Language: JavaScript
- Homepage: https://dai-siki.github.io/vue-image-crop-upload/example-2/demo.html
- Size: 1.65 MB
- Stars: 2,084
- Watchers: 39
- Forks: 367
- Open Issues: 120
-
Metadata Files:
- Readme: README-zh.md
Awesome Lists containing this project
- awesome-vue - vue-image-crop-upload - siki/vue-image-crop-upload?style=social) - vue图片剪裁上传组件 (UI组件)
- awesome-github-vue - vue-image-crop-upload - vue图片剪裁上传组件 (UI组件)
- awesome-vue - vue-image-crop-upload - vue图片剪裁上传组件 (UI组件)
- awesome-github-vue - vue-image-crop-upload - vue图片剪裁上传组件 (UI组件)
- awesome - vue-image-crop-upload - vue图片剪裁上传组件 (UI组件)
README
# vue-image-crop-upload
vue图片剪裁上传组件
**Notice**: (该组件适用于pc端,不推荐手机端使用)
[![GitHub issues](https://img.shields.io/github/issues/dai-siki/vue-image-crop-upload.svg)](https://github.com/dai-siki/vue-image-crop-upload/issues)
[![GitHub forks](https://img.shields.io/github/forks/dai-siki/vue-image-crop-upload.svg)](https://github.com/dai-siki/vue-image-crop-upload/network)
[![GitHub stars](https://img.shields.io/github/stars/dai-siki/vue-image-crop-upload.svg)](https://github.com/dai-siki/vue-image-crop-upload/stargazers)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/dai-siki/vue-image-crop-upload.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)[![NPM](https://nodei.co/npm/vue-image-crop-upload.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-image-crop-upload/)
## 更新日志
#### @3.0.0
- 兼容vue3## 示例
[点我](http://dai-siki.github.io/vue-image-crop-upload/example-3/demo.html).## 截图
![screenshot](screenshot/2.png)## 浏览器兼容
IE10+## 安装
#### npm
```shell
$ npm install vue-image-crop-upload
```## 使用
#### Props
| 名称 | 类型 | 默认 | 说明 |
| ----------------| ---------------- | ---------------| ------------------------------------------|
| url | String | '' | 上传接口地址,如果为空,图片不会上传 |
| method | String | 'POST' | 上传方法 |
| field | String | 'upload' | 向服务器上传的文件名 |
| value | Boolean | twoWay | 是否显示控件,双向绑定 |
| params | Object | null | 上传附带其他数据,格式"{k:v}" |
| headers | Object | null | 上传header设置,格式"{k:v}" |
| langType | String | 'zh' | 语言类型,默认中文 |
| langExt | Object | | 语言包自行扩展 |
| width | Number | 200 | 最终得到的图片宽度 |
| height | Number | 200 | 最终得到的图片高度 |
| imgFormat | string | 'png' | jpg/png, 最终得到的图片格式 |
| imgBgc | string | '#fff' | 导出图片背景色,当imgFormat属性为jpg时生效 |
| noCircle | Boolean | false | 关闭 圆形图像预览 |
| noSquare | Boolean | false | 关闭 方形图像预览 |
| noRotate | Boolean | true | 关闭 旋转图像功能 |
| withCredentials | Boolean | false | 支持跨域 |#### Events
| 名称 | 说明 |
| ----------------| ------------------------------------------|
| srcFileSet |用户选取文件之后, 参数( fileName, fileType, fileSize ) |
| cropSuccess | 图片截取完成事件(上传前), 参数( imageDataUrl, field ) |
| cropUploadSuccess | 上传成功, 参数( jsonData, field ) |
| cropUploadFail | 上传失败, 参数( status, field ) |#### langExt示例
```js
{
hint: '点击,或拖动图片至此处',
loading: '正在上传……',
noSupported: '浏览器不支持该功能,请使用IE10以上或其他现在浏览器!',
success: '上传成功',
fail: '图片上传失败',
preview: '头像预览',
btn: {
off: '取消',
close: '关闭',
back: '上一步',
save: '保存'
},
error: {
onlyImg: '仅限图片格式',
outOfSize: '单文件大小不能超过 ',
lowestPx: '图片最低像素为(宽*高):'
}
}
```#### 使用示例 vue@1
```htmlimport 'babel-polyfill'; // es6 shim
import Vue from 'vue';
import myUpload from 'vue-image-crop-upload/upload-1.vue';new Vue({
el: '#app',
data: {
show: true,
params: {
token: '123456798',
name: 'avatar'
},
headers: {
smail: '*_~'
},
imgDataUrl: '' // the datebase64 url of created image
},
components: {
'my-upload': myUpload
},
methods: {
toggleShow() {
this.show = !this.show;
}
},
events: {
/**
* crop success
*
* [param] imgDataUrl
* [param] field
*/
cropSuccess(imgDataUrl, field){
console.log('-------- crop success --------');
this.imgDataUrl = imgDataUrl;
},
/**
* upload success
*
* [param] jsonData 服务器返回数据,已进行json转码
* [param] field
*/
cropUploadSuccess(jsonData, field){
console.log('-------- upload success --------');
console.log(jsonData);
console.log('field: ' + field);
},
/**
* upload fail
*
* [param] status server api return error status, like 500
* [param] field
*/
cropUploadFail(status, field){
console.log('-------- upload fail --------');
console.log(status);
console.log('field: ' + field);
}
}
});```
#### 使用示例 vue@2
```htmlimport 'babel-polyfill'; // es6 shim
import Vue from 'vue';
import myUpload from 'vue-image-crop-upload/upload-2.vue';new Vue({
el: '#app',
data: {
show: true,
params: {
token: '123456798',
name: 'avatar'
},
headers: {
smail: '*_~'
},
imgDataUrl: '' // the datebase64 url of created image
},
components: {
'my-upload': myUpload
},
methods: {
toggleShow() {
this.show = !this.show;
},
/**
* crop success
*
* [param] imgDataUrl
* [param] field
*/
cropSuccess(imgDataUrl, field){
console.log('-------- crop success --------');
this.imgDataUrl = imgDataUrl;
},
/**
* upload success
*
* [param] jsonData 服务器返回数据,已进行json转码
* [param] field
*/
cropUploadSuccess(jsonData, field){
console.log('-------- upload success --------');
console.log(jsonData);
console.log('field: ' + field);
},
/**
* upload fail
*
* [param] status server api return error status, like 500
* [param] field
*/
cropUploadFail(status, field){
console.log('-------- upload fail --------');
console.log(status);
console.log('field: ' + field);
}
}
});```
#### 使用示例 vue@3
```htmlimport 'babel-polyfill'; // es6 shim
import Vue from 'vue';
import myUpload from 'vue-image-crop-upload';new Vue({
el: '#app',
data: {
show: true,
params: {
token: '123456798',
name: 'avatar'
},
headers: {
smail: '*_~'
},
imgDataUrl: '' // the datebase64 url of created image
},
components: {
'my-upload': myUpload
},
methods: {
toggleShow() {
this.show = !this.show;
},
/**
* crop success
*
* [param] imgDataUrl
* [param] field
*/
cropSuccess(imgDataUrl, field){
console.log('-------- crop success --------');
this.imgDataUrl = imgDataUrl;
},
/**
* upload success
*
* [param] jsonData 服务器返回数据,已进行json转码
* [param] field
*/
cropUploadSuccess(jsonData, field){
console.log('-------- upload success --------');
console.log(jsonData);
console.log('field: ' + field);
},
/**
* upload fail
*
* [param] status server api return error status, like 500
* [param] field
*/
cropUploadFail(status, field){
console.log('-------- upload fail --------');
console.log(status);
console.log('field: ' + field);
}
}
});```