Commit 12e0b7a 1 parent 6d38c6d commit 12e0b7a Copy full SHA for 12e0b7a
File tree 4 files changed +119
-15
lines changed
4 files changed +119
-15
lines changed Original file line number Diff line number Diff line change
1
+ import { shallowMount , mount } from '@vue/test-utils'
2
+ import Notify from '../notify.vue' ;
3
+ import Vue from 'vue' ;
4
+
5
+
6
+ describe ( 'notify.vue' , ( ) => {
7
+ const wrapper = shallowMount ( Notify , {
8
+ propsData : {
9
+ type : 'warn' ,
10
+ msg : "通知内容"
11
+ }
12
+ } ) ;
13
+
14
+ it ( '自定义背景色和字体颜色' , ( ) => {
15
+ wrapper . setProps ( {
16
+ color : '#ad0000' ,
17
+ background : '#ffe1e1'
18
+ } ) ;
19
+ return Vue . nextTick ( ) . then ( function ( ) {
20
+ expect ( wrapper . find ( '.nut-notify' ) . hasStyle ( 'color' , '#ad0000' ) ) . toBe ( true ) ;
21
+ expect ( wrapper . find ( '.nut-notify' ) . hasStyle ( 'background' , '#ffe1e1' ) ) . toBe ( true ) ;
22
+ } )
23
+ } ) ;
24
+ // it('自定义时长', () => {
25
+ // wrapper.setProps({
26
+ // color: '#ad0000',
27
+ // background: '#ffe1e1'
28
+ // });
29
+ // return Vue.nextTick().then(function () {
30
+ // expect(wrapper.find('.nut-notify').hasStyle('color', '#ad0000')).toBe(true);
31
+ // expect(wrapper.find('.nut-notify').hasStyle('background', '#ffe1e1')).toBe(true);
32
+ // })
33
+ // });
34
+ } ) ;
Original file line number Diff line number Diff line change 60
60
<label >组件调用</label >
61
61
</span >
62
62
</nut-cell >
63
- <nut-notify :showPopup =" show" type =" success" msg =" 组件调用 " >
64
- <span >hello</span >
63
+ <nut-notify :showPopup =" show" type =" success" msg =" hello " duration = " 10000 " >
64
+ <!-- < span>hello</span> -- >
65
65
</nut-notify >
66
66
</div >
67
67
<h4 >修改默认配置</h4 >
@@ -129,7 +129,7 @@ export default {
129
129
this .show = true ;
130
130
setTimeout (() => {
131
131
this .show = false ;
132
- }, 2000 );
132
+ }, 200 );
133
133
},
134
134
defaultNotify () {
135
135
this .$notify .setDefaultOptions ({
Original file line number Diff line number Diff line change 2
2
3
3
## 基本用法
4
4
5
- ``` html
6
- <nut-noticebar
7
- text =" 华为畅享9新品即将上市,活动期间0元预约可参与抽奖,赢HUAWEI WATCH等好礼,更多产品信息请持续关注!"
8
- ></nut-noticebar >
5
+ 文字提示
6
+ ``` javascript
7
+ export default {
8
+ mounted () {
9
+ this .$notify .text (' 通知内容' , {
10
+ onClosed () {
11
+ console .log (' close' );
12
+ },
13
+ onClick : () => {
14
+ console .log (' click' );
15
+ },
16
+ onOpened : () => {
17
+ console .log (' opened' );
18
+ }
19
+ });
20
+ }
21
+ }
9
22
```
10
23
## 通知类型
11
- 文字内容多于一行时,可通过scrollable参数控制是否开启滚动
12
- ``` html
13
- <nut-noticebar
14
- text =" 华为畅享9新品即将上市,活动期间0元预约可参与抽奖,赢HUAWEI WATCH等好礼,更多产品信息请持续关注!"
15
- :scrollable =" false"
16
- ></nut-noticebar >
24
+ ### 主要通知
25
+ ``` javascript
26
+ mounted (){
27
+ this .$notify .primary (' 通知内容' );
28
+ }
29
+ ```
30
+ ### 成功通知
31
+ ``` javascript
32
+ mounted (){
33
+ this .$notify .success (' 通知内容' );
34
+ }
35
+ ```
36
+ ### 危险通知
37
+ ``` javascript
38
+ mounted (){
39
+ this .$notify .danger (' 通知内容' );
40
+ }
41
+ ```
42
+ ### 警告通知
43
+ ``` javascript
44
+ mounted (){
45
+ this .$notify .warn (' 通知内容' );
46
+ }
17
47
```
18
48
## 自定义样式
49
+ ### 自定义样式
50
+ ``` javascript
51
+ mounted (){
52
+ this .$notify .text (val, {
53
+ color: ' #ad0000' ,
54
+ background: ' #ffe1e1'
55
+ });
56
+ }
57
+ ```
58
+ ### 自定义时长
59
+ ``` javascript
60
+ mounted (){
61
+ this .$notify .text (val, {
62
+ duration: 10000
63
+ });
64
+ }
65
+ ```
66
+ ## 组件调用
67
+ ``` html
68
+ <nut-notify :showPopup =" show" type =" success" msg =" 组件调用" >
69
+ <span >hello</span >
70
+ </nut-notify >
71
+ ```
19
72
73
+ ``` javascript
74
+ mounted (){
75
+ this .show = true ;
76
+ setTimeout (() => {
77
+ this .show = false ;
78
+ }, 2000 );
79
+ }
80
+ ```
81
+ ## 修改默认配置
82
+ 通过** Notify.setDefaultOptions** 函数可以全局修改 Notify 的默认配置,** 值得注意的是,标签形式的组件不支持默认样式** 。
83
+ ``` javascript
84
+ // 更改所有Toast展示时长设置为5000毫秒
85
+ this .$notify .setDefaultOptions ({
86
+ duration: 5000
87
+ });
88
+ // 重置所有 Toast 的默认配置
89
+ this .$notify .resetDefaultOptions ();
90
+ ```
20
91
21
92
22
93
45
116
| 方法名 | 说明 | 参数 | 返回值 |
46
117
| -------------------------- | -------------------------------- | ------- | ------- |
47
118
| Notify | 提示的信息 | options | message | notify 实例 |
48
- | Notify.clear | 关闭提示 | - | void |
49
119
| Notify.setDefaultOptions | 修改默认配置,对所有 Notify 生效 | options | void |
50
120
| Notify.resetDefaultOptions | 重置默认配置,对所有 Notify 生效 | String | void |
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import './notify.scss';
5
5
const NotifyArr = [ Notify , NotifyVue ] ;
6
6
// console.log(NotifyArr, Notify.text('Notify'));
7
7
NotifyArr . install = function ( Vue ) {
8
- Vue . prototype [ '$notify' ] = Notify ;
8
+ // Vue.prototype['$notify'] = Notify;
9
9
Vue . component ( NotifyVue . name , NotifyVue ) ;
10
10
} ;
11
11
You can’t perform that action at this time.
0 commit comments