[Improvement] Toast: support Vue.use to register (#690)
This commit is contained in:
@@ -69,7 +69,7 @@ Dialog.resetDefaultOptions = () => {
|
||||
};
|
||||
|
||||
Dialog.install = () => {
|
||||
Vue.component(VanDialog.name, VanDialog);
|
||||
Vue.use(VanDialog);
|
||||
};
|
||||
|
||||
Vue.prototype.$dialog = Dialog;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -86,6 +86,10 @@ Toast.allowMultiple = (allow = true) => {
|
||||
singleton = !allow;
|
||||
};
|
||||
|
||||
Toast.install = () => {
|
||||
Vue.use(VueToast);
|
||||
};
|
||||
|
||||
Vue.prototype.$toast = Toast;
|
||||
|
||||
export default Toast;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user