Skip to content

Commit

Permalink
fix(toast): function undefined bug #444
Browse files Browse the repository at this point in the history
  • Loading branch information
richard1015 committed Apr 15, 2021
1 parent 15dc7a9 commit 5e5acec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
15 changes: 6 additions & 9 deletions src/packages/toast/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,25 @@
</template>

<script>
import { getCurrentInstance } from 'vue';
import { createComponent } from '@/utils/create';
const { createDemo } = createComponent('toast');
import { Toast } from '@/nutui';
export default createDemo({
setup() {
const { proxy } = getCurrentInstance();
const textToast = msg => {
proxy.$toast.text(msg);
Toast.text(msg);
};
const successToast = msg => {
proxy.$toast.success(msg);
Toast.success(msg);
};
const errorToast = msg => {
proxy.$toast.fail(msg);
Toast.fail(msg);
};
const warningToast = msg => {
proxy.$toast.warn(msg);
Toast.warn(msg);
};
const loadingToast = msg => {
proxy.$toast.loading(msg);
Toast.loading(msg);
};
return {
textToast,
Expand Down
25 changes: 11 additions & 14 deletions src/packages/toast/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createVNode, defineComponent, render, App } from 'vue';
import VueToast from './index.vue';
const ToastConstructor = defineComponent(VueToast);
import { createVNode, render } from 'vue';
import Toast from './index.vue';
const defaultOptions = {
msg: '',
id: '',
Expand Down Expand Up @@ -52,7 +51,7 @@ const updateToast = (opts: any) => {
} else {
opts = { ...defaultOptions, ...opts };
}
const instance: any = createVNode(ToastConstructor, opts);
const instance: any = createVNode(Toast, opts);
render(instance, container);
return instance.component.ctx;
}
Expand All @@ -76,7 +75,7 @@ const mountToast = (opts: any) => {
optsMap.push(opts);
const container = document.createElement('div');
container.id = opts.id;
const instance: any = createVNode(ToastConstructor, opts);
const instance: any = createVNode(Toast, opts);
render(instance, container);
document.body.appendChild(container);
return instance.component.ctx;
Expand All @@ -89,7 +88,7 @@ const errorMsg = (msg: string) => {
}
};

export const Toast = {
export const ToastFunction = {
text(msg: string, opts = {}) {
errorMsg(msg);
return mountToast({ ...opts, type: 'text', msg });
Expand All @@ -116,14 +115,12 @@ export const Toast = {
},
hide() {
clearToast();
},
install(app: any): void {
app.use(Toast);
app.config.globalProperties.$toast = ToastFunction;
}
};

// export default Toast;

export default {
install(app: App): void {
app.config.globalProperties.$toast = Toast;
},
Toast
};
export { Toast };
export default ToastFunction;

0 comments on commit 5e5acec

Please sign in to comment.