├── babel.config.js ├── example ├── image-loader.gif ├── vue2.vue └── vue3.vue ├── vue.config.js ├── .npmignore ├── src ├── index.ts └── components │ └── VueLoadImage.vue ├── .eslintrc.js ├── .gitignore ├── LICENSE ├── package.json ├── README-ko.md └── README.md /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@vue/cli-plugin-babel/preset'], 3 | } 4 | -------------------------------------------------------------------------------- /example/image-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john015/vue-load-image/HEAD/example/image-loader.gif -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | productionSourceMap: false, 3 | css: { extract: false }, 4 | }; 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .git* 3 | .idea 4 | Makefile 5 | docs/ 6 | example/ 7 | config/ 8 | .eslintrc.js 9 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import VueLoadImage from './components/VueLoadImage.vue' 2 | 3 | export default VueLoadImage 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: ['plugin:vue/vue3-essential', 'eslint:recommended'], 7 | parserOptions: { 8 | parser: 'babel-eslint', 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directories # 2 | ########################## 3 | node_modules/ 4 | .yarn-integrity 5 | .npm 6 | 7 | # Logs and databases # 8 | ###################### 9 | *.log 10 | 11 | # OS generated files # 12 | .DS_Store 13 | ###################### 14 | .DS_Store? 15 | ._* 16 | .Spotlight-V100 17 | .Trashes 18 | ehthumbs.db 19 | Thumbs.db 20 | 21 | dist/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2019 John015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-load-image", 3 | "version": "1.1.0", 4 | "description": "A vue component for showing loader during image loading", 5 | "scripts": { 6 | "build": "vue-cli-service build --target=lib src/index.ts" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git://github.com/john015/vue-load-image.git" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/john015/vue-load-image/issues" 14 | }, 15 | "keywords": [ 16 | "vue-component", 17 | "vue", 18 | "vue-image-loader", 19 | "image-loader", 20 | "loader", 21 | "image", 22 | "image-preloader" 23 | ], 24 | "main": "./dist/vue-load-image.common.js", 25 | "browser": "./dist/vue-load-image.umd.min.js", 26 | "author": "Sangwon Lee ", 27 | "license": "MIT", 28 | "peerDependencies": { 29 | "vue": "^3" 30 | }, 31 | "devDependencies": { 32 | "@vue/cli-plugin-babel": "^4.5.13", 33 | "@vue/cli-plugin-eslint": "^4.5.13", 34 | "@vue/cli-service": "^4.5.13", 35 | "@vue/compiler-sfc": "^3.1.2", 36 | "babel-eslint": "^10.1.0", 37 | "eslint": "^6.7.2", 38 | "eslint-plugin-vue": "^7.12.1", 39 | "vue": "^3" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /example/vue2.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 33 | 34 | 50 | -------------------------------------------------------------------------------- /example/vue3.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 37 | 38 | 54 | -------------------------------------------------------------------------------- /src/components/VueLoadImage.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 113 | -------------------------------------------------------------------------------- /README-ko.md: -------------------------------------------------------------------------------- 1 | [English](./README.md) | 한국어 2 | 3 | # vue-load-image 4 | 5 | [![npm](https://img.shields.io/npm/dt/vue-load-image.svg)](https://www.npmjs.com/package/vue-load-image) ![npm bundle size (minified)](https://img.shields.io/bundlephobia/minzip/vue-load-image.svg) [![npm version](https://img.shields.io/npm/v/vue-load-image.svg?style=flat)](https://www.npmjs.com/package/vue-load-image) [![NpmLicense](https://img.shields.io/npm/l/vue-load-image.svg)](https://github.com/john015/vue-load-image/blob/master/LICENSE) 6 | 7 | vue-load-image 는 이미지로드 중 이미지 로더를 표시하며 이미지로드에 실패 했을때 대체 내용을 표시하는 1KB(gzipped size) Vue component 입니다. 8 | 9 | ## Demo 10 | 11 | [vue-load-image Demo](https://john015.github.io/vue-load-image/) / [(Source Code)](https://github.com/john015/vue-load-image/tree/master/example) 12 | 13 | ## Installation 14 | 15 | ### Via NPM: 16 | 17 | ```bash 18 | # for Vue 2.x 19 | npm i vue-load-image 20 | 21 | # for Vue 3.x 22 | npm i vue-load-image@next 23 | ``` 24 | 25 | ### Via CDN: 26 | 27 | ```html 28 | 29 | 30 | 31 | 32 | 33 | ``` 34 | 35 | ## Usage 36 | 37 | ### Image 38 | 39 | #### Vue 2.x 40 | 41 | ```js 42 | 51 | 52 | 61 | ``` 62 | 63 | #### Vue 3.x 64 | 65 | ```js 66 | 79 | 80 | 89 | ``` 90 | 91 | ### Background-image 92 | 93 | #### Vue 2.x 94 | 95 | ```js 96 | 105 | 106 | 115 | ``` 116 | 117 | #### Vue 3.x 118 | 119 | ```js 120 | 133 | 134 | 143 | ``` 144 | 145 | #### ⚠️유의사항 146 | 147 | data-src 값을 background-image url 과 동일하게 설정 해주세요. 148 | 149 | ## Events 150 | 151 | | Name | Description | 152 | | --------- | ------------------------------------------ | 153 | | `onError` | 이미지 로드 실패시 onError 가 호출 됩니다. | 154 | | `onLoad` | 이미지가 로드되면 onLoad 가 호출 됩니다. | 155 | 156 | ## Slots 157 | 158 | 이미지가 성공적으로 로드 되면 "image" slot 이 렌더링 됩니다. 159 | 160 | 이미지가 로드 중일 때 "preloader" slot 이 렌더링됩니다. 161 | 162 | 이미지로드에 실패하면 "error" slot 이 렌더링됩니다. 163 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | English | [한국어](./README-ko.md) 2 | 3 | # Vue-load-image 4 | 5 | [![npm](https://img.shields.io/npm/dt/vue-load-image.svg)](https://www.npmjs.com/package/vue-load-image) ![npm bundle size (minified)](https://img.shields.io/bundlephobia/minzip/vue-load-image.svg) [![npm version](https://img.shields.io/npm/v/vue-load-image.svg?style=flat)](https://www.npmjs.com/package/vue-load-image) [![NpmLicense](https://img.shields.io/npm/l/vue-load-image.svg)](https://github.com/john015/vue-load-image/blob/master/LICENSE) 6 | 7 | Vue-load-image is 1KB(gzipped size) minimalist Vue component that display loader during image loading and display alternate content when the image fails to load. 8 | 9 | ## Demo 10 | 11 | [vue-load-image Demo](https://john015.github.io/vue-load-image/) / [(Source Code)](https://github.com/john015/vue-load-image/tree/master/example) 12 | 13 | ## Installation 14 | 15 | ### Via NPM: 16 | 17 | ```bash 18 | # for Vue 2.x 19 | npm i vue-load-image 20 | 21 | # for Vue 3.x 22 | npm i vue-load-image@next 23 | ``` 24 | 25 | ### Via CDN: 26 | 27 | ```html 28 | 29 | 30 | 31 | 32 | 33 | ``` 34 | 35 | ## Usage 36 | 37 | ### Image 38 | 39 | #### Vue 2.x 40 | 41 | ```js 42 | 51 | 52 | 61 | ``` 62 | 63 | #### Vue 3.x 64 | 65 | ```js 66 | 79 | 80 | 89 | ``` 90 | 91 | ### Background-image 92 | 93 | #### Vue 2.x 94 | 95 | ```js 96 | 105 | 106 | 115 | ``` 116 | 117 | #### Vue 3.x 118 | 119 | ```js 120 | 133 | 134 | 143 | ``` 144 | 145 | #### ⚠️Notice 146 | 147 | Set data-src to be the same as background-image url 148 | 149 | ## Events 150 | 151 | | Name | Description | 152 | | --------- | ---------------------------------------------------- | 153 | | `onError` | onError gets triggered when the image fails to load. | 154 | | `onLoad` | onLoad gets triggered when the image is loaded. | 155 | 156 | ## Slots 157 | 158 | `"image"` slot will be rendered when the image is successfully loaded 159 | 160 | `"preloader"` slot will be rendered when the image is in the process of loading 161 | 162 | `"error"` slot will be rendered when the image load fails. 163 | --------------------------------------------------------------------------------