Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-image-crop-upload

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-image-crop-upload

a vue plgin for image upload and crop(vue图片剪裁上传插件)

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
decreased by-5.74%
Maintainers
1
Weekly downloads
 
Created
Source

vue-image-crop-upload

A beautiful vue component for image crop and upload. (vue图片剪裁上传组件)

中文文档在下面

Demo

Click me.

Screenshot

screenshot

Brower compatibility

IE10+

Env

vue@1.0 + webpack + es6

Install

npm
$ npm install vue-image-crop-upload

Usage

Props
名称类型默认说明
fieldString'upload'Upload input filename, used for server side get the file stream.
valueBooleantwoWayshow or not
urlString''Server api path,like "/avatar/upload"
otherParamsObjectnullPOST Params,like "{k:v}"
langTypeString'zh'language type
langConfObjectlanguage extend
widthNumber200width of receive image
heightNumber200height of receive image
imgFormatstring'jpg'jpg/png, Server api receive file type.
Events
名称说明
cropSuccessimage crop success, params( imageUrl, field )
cropUploadSuccessupload success, params( jsonData, field )
cropUploadFailupload fail, params( status, field )
Language package
{
    zh: {
        hint: '点击,或拖动图片至此处',
        loading: '正在上传……',
        noSupported: '浏览器不支持该功能,请使用IE10以上或其他现在浏览器!',
        success: '上传成功',
        preview: '头像预览',
        btn: {
            off: '取消',
            close: '关闭',
            back: '上一步',
            save: '保存'
        },
        error: {
            onlyImg: '仅限图片格式',
            outOfSize: '单文件大小不能超过 ',
            lowestPx: '图片最低像素为(宽*高):'
        }
    },
    en: {
        hint: 'Click, or drag picture to there',
        loading: 'Uploading……',
        noSupported: 'Browser not supported, please use IE10+ or else browser',
        success: 'Upload success',
        preview: 'Preview',
        btn: {
            off: 'Off',
            close: 'Close',
            back: 'Back',
            save: 'Save'
        },
        error: {
            onlyImg: 'Only image',
            outOfSize: 'Image is out of size: ',
            lowestPx: 'Image lowest pixel(width*height):'
        }
    }
};
Example
<div id="app">
	<a class="btn" @click="toggleShow">set avatar</a>
	<my-upload url="/upload" field="img"
        lang-type="en"
		:value.sync="show"
		:other-params="otherParams"></my-upload>
</div>

<script>
	import 'babel-polyfill'; // es6 shim
	import Vue from 'vue';
	import mySwitch from 'vue-image-crop-upload';

	new Vue({
		el: '#app',
		data: {
			show: true,
			otherParams: {
				token: '123456798',
				name: 'avatar'
			}
		},
		components: {
			'my-upload': myUpload
		},
		methods: {
			toggleShow() {
				this.show = !this.show;
			}
		},
		events: {
            /**
			 * crop success
			 *
			 * [param] jsonData
			 * [param] field
			 */
			cropSuccess(jsonData, field){
				console.log('-------- upload success --------');
				console.log(jsonData);
				console.log('field: ' + field);
			},
			/**
			 * upload success
			 *
			 * [param] jsonData   server api return data, already json encode
			 * [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);
			}
		}
	});

</script>

示例

点我.

截图

screenshot

浏览器兼容

IE10+

配置环境

vue@1.0 + webpack + es6

安装

npm
$ npm install vue-image-crop-upload

使用

Props
名称类型默认说明
fieldString'upload'向服务器上传的文件名
valueBooleantwoWay是否显示控件,双向绑定
urlString''上传接口地址
otherParamsObjectnull上传附带其他数据,如"{k:v}"
langTypeString'zh'语言类型,默认中文
langConfObject语言包自行扩展
widthNumber200最终得到的图片宽度
heightNumber200最终得到的图片高度
imgFormatstring'jpg'jpg/png, 最终得到的图片格式
Events
名称说明
cropSuccess图片截取完成事件(上传前), 参数( imageUrl, field )
cropUploadSuccess上传成功, 参数( jsonData, field )
cropUploadFail上传失败, 参数( status, field )
自带语言包
{
    zh: {
        hint: '点击,或拖动图片至此处',
        loading: '正在上传……',
        noSupported: '浏览器不支持该功能,请使用IE10以上或其他现在浏览器!',
        success: '上传成功',
        preview: '头像预览',
        btn: {
            off: '取消',
            close: '关闭',
            back: '上一步',
            save: '保存'
        },
        error: {
            onlyImg: '仅限图片格式',
            outOfSize: '单文件大小不能超过 ',
            lowestPx: '图片最低像素为(宽*高):'
        }
    },
    en: {
        hint: 'Click, or drag picture to there',
        loading: 'Uploading……',
        noSupported: 'Browser not supported, please use IE10+ or else browser',
        success: 'Upload success',
        preview: 'Preview',
        btn: {
            off: 'Off',
            close: 'Close',
            back: 'Back',
            save: 'Save'
        },
        error: {
            onlyImg: 'Only image',
            outOfSize: 'Image is out of size: ',
            lowestPx: 'Image lowest pixel(width*height):'
        }
    }
};
使用示例
<div id="app">
	<a class="btn" @click="toggleShow">设置头像</a>
	<my-upload url="/upload" field="img"
        lang-type="en"
		:value.sync="show"
		:other-params="otherParams"></my-upload>
</div>

<script>
	import 'babel-polyfill'; // es6 shim
	import Vue from 'vue';
	import mySwitch from 'vue-image-crop-upload';

	new Vue({
		el: '#app',
		data: {
			show: true,
			otherParams: {
				token: '123456798',
				name: 'avatar'
			}
		},
		components: {
			'my-upload': myUpload
		},
		methods: {
			toggleShow() {
				this.show = !this.show;
			}
		},
		events: {
            /**
			 * crop success
			 *
			 * [param] jsonData
			 * [param] field
			 */
			cropSuccess(jsonData, field){
				console.log('-------- upload success --------');
				console.log(jsonData);
				console.log('field: ' + field);
			},
			/**
			 * 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);
			}
		}
	});

</script>

Keywords

FAQs

Package last updated on 23 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc