Skip to content

Commit

Permalink
allow locally register
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisniu committed Mar 11, 2022
1 parent ee90b8e commit abf4cfa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ This library has released a Vue 3 beta version [here](https://github.com/jarvisn

## Demo

- [Single Image](https://unpkg.com/vue-zoomer/dist/demo/basic.html)
- [Gallery](https://unpkg.com/vue-zoomer/dist/demo/gallery.html)
- [Single Image](https://unpkg.com/vue-zoomer/dist/demo/basic.html) -
[(src)](https://github.com/jarvisniu/vue-zoomer/blob/master/demo/basic/app.vue)
- [Gallery](https://unpkg.com/vue-zoomer/dist/demo/gallery.html) -
[(src)](https://github.com/jarvisniu/vue-zoomer/blob/master/demo/gallery/app.vue)

## Usage

Expand All @@ -19,7 +21,7 @@ Install:
npm install vue-zoomer
```

Import:
Import and register globally:

```js
import Vue from 'vue'
Expand All @@ -28,6 +30,28 @@ import VueZoomer from 'vue-zoomer'
Vue.use(VueZoomer)
```

Import and register locally (after `v0.3.10`):

```html
<!-- page1.vue -->
<script>
import VueZoomer from 'vue-zoomer'
export default {
components: {
VZoomer: VueZoomer.Zoomer,
VZoomerGallery: VueZoomer.Gallery,
},
}
</script>
```

You can also import the source files (after `v0.3.10`), rather than
the minified umd bundle, for better debugging experience:
```js
import VueZoomer from 'vue-zoomer/src'
```

Single usage:

```html
Expand Down
12 changes: 10 additions & 2 deletions demo/basic/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
</div>
<v-zoomer
ref="zoomer"
style="width: 500px; height: 500px; border: solid 1px silver;"
style="width: 800px; height: 500px; border: solid 1px silver;"
:aspect-ratio="imageAspectRatio"
:max-scale="10"
:zooming-elastic="false"
:zoomed.sync="zoomed"
>
<img src="../assets/landscape-1.jpg" style="object-fit: contain; width: 100%; height: 100%;">
<img src="../assets/landscape-1.jpg" style="object-fit: contain; width: 100%; height: 100%;" @load="onImageLoad">
</v-zoomer>
</div>
</template>
Expand All @@ -22,7 +23,14 @@ export default {
data () {
return {
zoomed: false,
imageAspectRatio: 1,
}
},
methods: {
onImageLoad(e) {
const img = e.target
this.imageAspectRatio = img.naturalWidth / img.naturalHeight
},
},
}
</script>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-zoomer",
"version": "0.3.9",
"version": "0.3.10",
"description": "Zoom the image or other thing with mouse or touch",
"main": "dist/vue-zoomer.min.js",
"module": "dist/vue-zoomer.esm.js",
Expand Down Expand Up @@ -35,6 +35,7 @@
"vue-template-compiler": "^2.6.7"
},
"files": [
"src/**/*",
"dist/**/*"
]
}
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export { default as VueZoomer } from './vue-zoomer.vue'
export { default as VueZoomerGallery } from './vue-zoomer-gallery.vue'
import VueZoomer from './vue-zoomer.vue'
import VueZoomerGallery from './vue-zoomer-gallery.vue'

export default {
install (Vue) {
Vue.component('VZoomer', VueZoomer)
Vue.component('VZoomerGallery', VueZoomerGallery)
},
// for locally register
Zoomer: VueZoomer,
Gallery: VueZoomerGallery,
}

0 comments on commit abf4cfa

Please sign in to comment.