[bugfix] Toast: ssr error (#1910)

This commit is contained in:
neverland 2018-10-09 18:12:02 +08:00 committed by GitHub
parent bcfa4ed3ac
commit 6858f4e2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 8 deletions

View File

@ -14,9 +14,9 @@ module.exports = {
'!**/vant-css/**',
'!**/demo/**',
'!**/locale/lang/**',
'!**/waterfall/**',
'!**/sku/**',
'!**/lazyload/**'
'!**/waterfall/**',
'!**/icon/config/**'
],
collectCoverage: true,
coverageReporters: ['html', 'lcov', 'text-summary'],

View File

@ -69,7 +69,7 @@
</van-button>
</div>
<popup v-model="showAreaPopup" position="bottom" :lazy-render="false" :get-container="getAreaContainer">
<popup v-model="showAreaPopup" position="bottom" :lazy-render="false" get-container="body">
<van-area
ref="area"
:loading="!areaListLoaded"
@ -305,10 +305,6 @@ export default create({
setAddressDetail(value) {
this.data.addressDetail = value;
},
getAreaContainer() {
return document.body;
}
}
});

View File

@ -35,6 +35,7 @@ const createComponent = () => {
data,
field,
button,
wrapper,
errorInfo
};
};
@ -225,3 +226,15 @@ test('delete address', async() => {
expect(wrapper.emitted('delete')).toBeTruthy();
expect(wrapper.emitted('cancel-delete')).toBeTruthy();
});
test('setAddressDetail method', () => {
const { vm, data } = createComponent();
vm.setAddressDetail('test');
expect(data.addressDetail).toEqual('test');
});
test('select area', () => {
const { wrapper, data } = createComponent();
wrapper.find('.van-picker__confirm').trigger('click');
expect(data.areaCode).toEqual('110101');
});

View File

@ -1,5 +1,6 @@
import Vue from 'vue';
import VanDialog from './Dialog';
import { isServer } from '../utils';
let instance;
@ -16,6 +17,11 @@ const initInstance = () => {
};
const Dialog = options => {
/* istanbul ignore if */
if (isServer) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
if (!instance) {
initInstance();

View File

@ -1,5 +1,6 @@
import Vue from 'vue';
import VueImagePreview from './ImagePreview';
import { isServer } from '../utils';
let instance;
@ -11,6 +12,11 @@ const initInstance = () => {
};
const ImagePreview = (images, startPosition) => {
/* istanbul ignore if */
if (isServer) {
return;
}
if (!instance) {
initInstance();
}

View File

@ -136,6 +136,11 @@ export default create({
methods: {
handler(action) {
/* istanbul ignore if */
if (this.$isServer) {
return;
}
if (action !== this.handlerStatus && this.hideOnClickOutside) {
this.handlerStatus = action;
document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.onBlur);

View File

@ -1,6 +1,6 @@
import Vue from 'vue';
import VueToast from './Toast';
import { isObj } from '../utils';
import { isObj, isServer } from '../utils';
const defaultOptions = {
type: 'text',
@ -37,6 +37,11 @@ function transformer(options) {
}
function Toast(options = {}) {
/* istanbul ignore if */
if (isServer) {
return;
}
const toast = createInstance();
options = {