From 1e01b36bc2280dfa38765442d371103367a40a5f Mon Sep 17 00:00:00 2001
From: mason369 <1960638223@qq.com>
Date: Fri, 20 Jan 2023 17:53:30 +0800
Subject: [PATCH] =?UTF-8?q?update:=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1?=
=?UTF-8?q?=E5=AE=88=E5=8D=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 3 +-
src/components/Toast.vue | 62 ++++++++++++++++++++++++++++++++++++
src/router/index.js | 5 +--
src/store/index.js | 3 +-
src/store/showToast/index.js | 52 ++++++++++++++++++++++++++++++
5 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 src/components/Toast.vue
create mode 100644 src/store/showToast/index.js
diff --git a/package.json b/package.json
index 0ff5791..602d7a8 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,8 @@
"version": "1.0.0",
"private": true,
"scripts": {
- "serve": "vue-cli-service serve",
+ "serve": "vue-cli-service serve --mode dev",
+ "servepro": "vue-cli-service serve --mode prod",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
diff --git a/src/components/Toast.vue b/src/components/Toast.vue
new file mode 100644
index 0000000..eeead66
--- /dev/null
+++ b/src/components/Toast.vue
@@ -0,0 +1,62 @@
+
+
+
+
+
+ {{ msg }}
+
+
+
+
+
+
diff --git a/src/router/index.js b/src/router/index.js
index 97b2fef..b37fe9e 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,6 +1,7 @@
import Vue from "vue";
import VueRouter from "vue-router";
import routes from "./routes";
+import store from "@/store";
Vue.use(VueRouter);
@@ -38,8 +39,7 @@ VueRouter.prototype.replace = function(location, resolve, reject) {
}
};
-
-export default new VueRouter({
+const router = new VueRouter({
routes,
scrollBehavior() {
return { y: 0 };
@@ -48,3 +48,4 @@ export default new VueRouter({
mode: "hash"
});
+export default router;
diff --git a/src/store/index.js b/src/store/index.js
index 453eeac..e715f1b 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -3,7 +3,8 @@ import Vuex from "vuex";
import isShowLoginModal from "@/store/isShowLoginModal";
import loginStatus from "@/store/loginStatus";
import userInfo from "@/store/userInfo";
+import showToast from "@/store/showToast";
Vue.use(Vuex);
-export default new Vuex.Store({modules: { isShowLoginModal, loginStatus, userInfo }});
+export default new Vuex.Store({modules: { isShowLoginModal, loginStatus, userInfo, showToast }});
diff --git a/src/store/showToast/index.js b/src/store/showToast/index.js
new file mode 100644
index 0000000..b6ccfb1
--- /dev/null
+++ b/src/store/showToast/index.js
@@ -0,0 +1,52 @@
+export default {
+ namespaced: true,
+ state : {
+ // 显示与否 true 仅仅之决定了一个显示属性
+ // 提示文本 "登录成功"
+ // 提示类型 "sucess" "warning" "danger"
+ // 用来表示提示框的显示true或隐藏false
+ isShowToast: false,
+ msg : "",
+ type : ""
+ },
+ mutations: {
+ // 修改isShowToast的值
+ chanIsShowToast(state, payload) {
+ state.isShowToast = payload.isShow;
+ state.msg = payload.msg;
+ state.type = payload.type;
+ }
+ },
+ actions: {
+ asyncChanIsShowToast({ commit }, payload) {
+ // let {commit} = context
+ // 先展示,就是调用原先写的上面的这个方法chanIsShowToast
+ commit("chanIsShowToast", {
+ isShow: true,
+ msg : payload.msg,
+ type : payload.type
+ });
+
+ // 关闭的代码
+ setTimeout(() => {
+ commit("chanIsShowToast", {
+ isShow: false,
+ msg : payload.msg,
+ type : payload.type
+ });
+ }, 1500);
+ }
+ }
+};
+
+// 封装Toast组件总结:
+// 样式结构
+// 显示隐藏变量存在Vuex中
+// 过渡效果(进场离场)
+// msg和type属性处理
+// 定时器,关闭Toast组件
+// 抽取定时器到actions的方法中
+
+// 如何使用这个组件???
+
+//this.xxx({msg:"xxx", type:"success"}) 展示提示组件