diff --git a/package.json b/package.json
index ac23510..a9b5c75 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,8 @@
"version": "1.1.5",
"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"}) 展示提示组件