support Nuxt.js
This commit is contained in:
parent
825ed58099
commit
a68c11a565
4 changed files with 16 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* https://github.com/freeze-component/vue-popper
|
* https://github.com/freeze-component/vue-popper
|
||||||
* */
|
* */
|
||||||
import Popper from 'popper.js';
|
import Vue from 'vue';
|
||||||
|
const isServer = Vue.prototype.$isServer;
|
||||||
|
const Popper = isServer ? function() {} : require('popper.js'); // eslint-disable-line
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
@ -62,6 +64,7 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createPopper() {
|
createPopper() {
|
||||||
|
if (isServer) return;
|
||||||
if (!/^(top|bottom|left|right)(-start|-end)?$/g.test(this.placement)) {
|
if (!/^(top|bottom|left|right)(-start|-end)?$/g.test(this.placement)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,19 +90,23 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updatePopper() {
|
updatePopper() {
|
||||||
|
if (isServer) return;
|
||||||
this.popperJS ? this.popperJS.update() : this.createPopper();
|
this.popperJS ? this.popperJS.update() : this.createPopper();
|
||||||
},
|
},
|
||||||
doDestroy() {
|
doDestroy() {
|
||||||
|
if (isServer) return;
|
||||||
if (this.visible) return;
|
if (this.visible) return;
|
||||||
this.popperJS.destroy();
|
this.popperJS.destroy();
|
||||||
this.popperJS = null;
|
this.popperJS = null;
|
||||||
},
|
},
|
||||||
destroyPopper() {
|
destroyPopper() {
|
||||||
|
if (isServer) return;
|
||||||
if (this.popperJS) {
|
if (this.popperJS) {
|
||||||
this.resetTransformOrigin(this.popperJS);
|
this.resetTransformOrigin(this.popperJS);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetTransformOrigin(popper) {
|
resetTransformOrigin(popper) {
|
||||||
|
if (isServer) return;
|
||||||
let placementMap = {top: 'bottom', bottom: 'top', left: 'right', right: 'left'};
|
let placementMap = {top: 'bottom', bottom: 'top', left: 'right', right: 'left'};
|
||||||
let placement = popper._popper.getAttribute('x-placement').split('-')[0];
|
let placement = popper._popper.getAttribute('x-placement').split('-')[0];
|
||||||
let origin = placementMap[placement];
|
let origin = placementMap[placement];
|
||||||
|
@ -107,6 +114,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
if (isServer) return;
|
||||||
if (this.popperJS) {
|
if (this.popperJS) {
|
||||||
this.popperJS.destroy();
|
this.popperJS.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
<div class="ivu-select-dropdown" :style="styles"><slot></slot></div>
|
<div class="ivu-select-dropdown" :style="styles"><slot></slot></div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import Vue from 'vue';
|
||||||
|
const isServer = Vue.prototype.$isServer;
|
||||||
import { getStyle } from '../../utils/assist';
|
import { getStyle } from '../../utils/assist';
|
||||||
import Popper from 'popper.js';
|
const Popper = isServer ? function() {} : require('popper.js'); // eslint-disable-line
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Drop',
|
name: 'Drop',
|
||||||
|
@ -28,6 +30,7 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
update () {
|
update () {
|
||||||
|
if (isServer) return;
|
||||||
if (this.popper) {
|
if (this.popper) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.popper.update();
|
this.popper.update();
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import Vue from 'vue';
|
||||||
|
const isServer = Vue.prototype.$isServer;
|
||||||
// 判断参数是否是其中之一
|
// 判断参数是否是其中之一
|
||||||
export function oneOf (value, validList) {
|
export function oneOf (value, validList) {
|
||||||
for (let i = 0; i < validList.length; i++) {
|
for (let i = 0; i < validList.length; i++) {
|
||||||
|
@ -52,7 +54,7 @@ export function getScrollBarSize (fresh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// watch DOM change
|
// watch DOM change
|
||||||
export const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
|
export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
|
||||||
|
|
||||||
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
|
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
|
||||||
const MOZ_HACK_REGEXP = /^moz([A-Z])/;
|
const MOZ_HACK_REGEXP = /^moz([A-Z])/;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
const isServer = Vue.prototype.$isServer;
|
const isServer = Vue.prototype.$isServer;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
|
|
Loading…
Add table
Reference in a new issue