-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from School-of-Website-Engineering/develop
- Loading branch information
Showing
5 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<!-- 封装提示框组件 --> | ||
<!-- | ||
看type的值: | ||
success iconfont icon-toast_chenggong | ||
warning iconfont icon-toast-jinggao | ||
danger iconfont icon-toast-shibai_huaban | ||
--> | ||
<div class="toast"> | ||
<i | ||
:class=" | ||
type == 'success' | ||
? 'iconfont icon-toast_chenggong' | ||
: type == 'warning' | ||
? 'iconfont icon-toast-jinggao' | ||
: 'iconfont icon-toast-shibai_huaban' | ||
" | ||
></i> | ||
<span>{{ msg }}</span> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from "vuex"; | ||
export default { | ||
data() { | ||
return {}; | ||
}, | ||
computed: { | ||
...mapState({ | ||
msg : (state) => state.showToast.msg, | ||
type: (state) => state.showToast.type | ||
}) | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.toast { | ||
background-color: #fff; | ||
position: fixed; | ||
left: 50%; | ||
top: 0; | ||
transform: translateX(-50%); | ||
padding: 10px 20px; | ||
border-radius: 6px; | ||
box-shadow: 0 0 10px #fff; | ||
i { | ||
margin-right: 8px; | ||
} | ||
.icon-toast_chenggong { | ||
color: green; | ||
} | ||
.icon-toast-jinggao { | ||
color: orange; | ||
} | ||
.icon-toast-shibai_huaban { | ||
color: red; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}) 展示提示组件 |