[Improvement] Toast: support Vue.use to register (#690)

This commit is contained in:
neverland
2018-03-14 11:47:46 +08:00
committed by GitHub
parent 8f2bd93786
commit 461b6732eb
11 changed files with 36 additions and 18 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ Dialog.resetDefaultOptions = () => {
};
Dialog.install = () => {
Vue.component(VanDialog.name, VanDialog);
Vue.use(VanDialog);
};
Vue.prototype.$dialog = Dialog;
+8 -6
View File
@@ -1,18 +1,16 @@
import Vue from 'vue';
import ImagePreview from './image-preview';
import VueImagePreview from './image-preview';
let instance;
const ImagePreviewConstructor = Vue.extend(ImagePreview);
const initInstance = () => {
instance = new ImagePreviewConstructor({
instance = new (Vue.extend(VueImagePreview))({
el: document.createElement('div')
});
document.body.appendChild(instance.$el);
};
const ImagePreviewBox = (images, startPosition = 0) => {
const ImagePreview = (images, startPosition = 0) => {
if (!instance) {
initInstance();
}
@@ -27,4 +25,8 @@ const ImagePreviewBox = (images, startPosition = 0) => {
return instance;
};
export default ImagePreviewBox;
ImagePreview.install = () => {
Vue.use(VueImagePreview);
};
export default ImagePreview;
+3
View File
@@ -97,8 +97,10 @@ const components = [
GoodsActionBigBtn,
GoodsActionMiniBtn,
Icon,
ImagePreview,
List,
Loading,
Locale,
NavBar,
NoticeBar,
NumberKeyboard,
@@ -127,6 +129,7 @@ const components = [
TabbarItem,
Tabs,
Tag,
Toast,
TreeSelect,
Uploader
];
+6 -2
View File
@@ -5,7 +5,10 @@ import defaultMessages from './lang/zh-CN';
const proto = Vue.prototype;
const defaultLang = 'zh-CN';
const locale = {
init() {
install() {
if (proto.$vantLang) {
return;
}
Vue.util.defineReactive(proto, '$vantLang', defaultLang);
Vue.util.defineReactive(proto, '$vantMessages', { [defaultLang]: defaultMessages });
},
@@ -20,5 +23,6 @@ const locale = {
}
};
locale.init();
locale.install();
export default locale;
+4
View File
@@ -86,6 +86,10 @@ Toast.allowMultiple = (allow = true) => {
singleton = !allow;
};
Toast.install = () => {
Vue.use(VueToast);
};
Vue.prototype.$toast = Toast;
export default Toast;
+1 -2
View File
@@ -1,6 +1,6 @@
import Waterfall from './directive.js';
const install = function(Vue) {
Waterfall.install = function(Vue) {
if (process.env.NODE_ENV !== 'production') {
console.warn('[Vant warn] Waterfall is deprecated, please use List component instread.');
}
@@ -8,5 +8,4 @@ const install = function(Vue) {
Vue.directive('WaterfallUpper', Waterfall('upper'));
};
Waterfall.install = install;
export default Waterfall;