Skip to content

Commit

Permalink
feat(export): 修改导出方式
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengFeijie committed Oct 31, 2019
1 parent c0b8487 commit ed275d0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 36 deletions.
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,14 @@
import Vue from 'vue'
import vueObserverDirective from 'vue-observer-directive'
// 全局注册(自定义指令名默认是:observer)
Vue.use(vueObserverDirective, { directive: 'observer' })
```
```javascript
import Vue from 'vue'
import { vueObserverDirective } from 'vue-observer-directive'
// 全局注册
Vue.directive('observer', vueObserverDirective)
Vue.use(vueObserverDirective, { directive: 'observer' }) // 自定义指令名默认是:observer
// 或:Vue.directive('observer', vueObserverDirective)
```
2. 局部注册
```javascript
import { vueObserverDirective } from 'vue-observer-directive'
import vueObserverDirective from 'vue-observer-directive'
export default {
directives: {
Expand All @@ -61,9 +52,9 @@
<!-- 需要先引入vue-observer-directive:<script src="//unpkg.com/vue-observer-directive"></script> -->
<script>
// 全局注册(自定义指令名默认是:observer)
Vue.use(vueObserverDirective.default, { directive: 'observer' })
// 或:Vue.directive('observer', vueObserverDirective.vueObserverDirective)
// 全局注册
Vue.use(vueObserverDirective, { directive: 'observer' }) // 自定义指令名默认是:observer
// 或:Vue.directive('observer', vueObserverDirective)
</script>
```
2. 局部注册
Expand All @@ -76,7 +67,7 @@
new Vue({
directives: {
// 局部注册
observer: vueObserverDirective.vueObserverDirective
observer: vueObserverDirective
}
})
</script>
Expand Down
6 changes: 3 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

<script>
// 全局注册
// Vue.use(vueObserverDirective.default, { directive: 'observer2' })
// 或:Vue.directive('observer2', vueObserverDirective.vueObserverDirective)
// Vue.use(vueObserverDirective, { directive: 'observer2' })
// 或:Vue.directive('observer2', vueObserverDirective)

new Vue({
directives: {
// 局部注册
observer2: vueObserverDirective.vueObserverDirective
observer2: vueObserverDirective
},
el: '#app',
data () {
Expand Down
2 changes: 1 addition & 1 deletion dist/vue-observer-directive.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-observer-directive.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-observer-directive.iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"babelrc-rollup": "^3.0.0",
"rollup": "^1.25.2",
"rollup": "^1.26.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-terser": "^5.1.2"
},
"version": "1.2.3"
"version": "1.2.4"
}
16 changes: 4 additions & 12 deletions src/vue-observer-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function DisplayDom ({ target, show = () => {}, hide = () => {}, threshold = 0.0
}
}

const observer = { // v-observer:数字.once="{ show: ()=>{}, hide: ()=>{} }"
const vueObserverDirective = { // v-observer:数字.once="{ show: ()=>{}, hide: ()=>{} }"
inserted (el, { value, arg, modifiers }) {
el.observer = new DisplayDom({
target: el,
Expand All @@ -54,16 +54,8 @@ const observer = { // v-observer:数字.once="{ show: ()=>{}, hide: ()=>{} }"
}
}

const plugin = {
install (Vue, options = {}) {
Vue.directive(options.directive || 'observer', observer)
}
vueObserverDirective.install = (Vue, options = {}) => {
Vue.directive(options.directive || 'observer', vueObserverDirective)
}

export {
// 全局注册
plugin as default,

// 局部注册
observer as vueObserverDirective
}
export default vueObserverDirective

0 comments on commit ed275d0

Please sign in to comment.