-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.vue
186 lines (183 loc) · 5.02 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
<div id="app">
<easy-github-pages
:menus="menuList"
author="zhangchaojie"
githubUrl="https://github.com/dream2023/easy-affix/"
title="easy-affix | vue图钉组件"
>
<section id="intro">
<h2>介绍</h2>
<p>使用图钉,可以将内容固定在屏幕上,并且不随页面的滚动而滚动。常用于侧边菜单等。</p>
</section>
<section id="reason">
<h2>创作原因</h2>
<p>
其实在
<code>iview</code>和
<code>ant-design</code>框架中已有
affix组件, 但如果在小项目或者使用element之类的框架, 就没办法引入了(虽然可以同时安装两个框架,也可以按需引入, 但是不建议)。
</p>
<p>
另外, 网上虽然已有
<code>vue-affix</code>, 但是其必须指定相对元素, 而不可以默认跟随window, 所以和我的需求略微不同, 就动手做了一个。
</p>
</section>
<section id="install">
<h2>安装</h2>
<blockquote>npm install easy-affix --save</blockquote>
</section>
<section id="usage">
<h2>使用</h2>
<blockquote>
<pre class="language-js">
<code class="language-js">
// 局部引入
import Affix from 'easy-affix'
export default {
components: {
Affix
}
}
</code>
</pre>
</blockquote>
<blockquote>
<pre class="language-js">
<code class="language-js">
// 全局引入
import Affix from 'easy-affix'
Vue.component('affix', Affix)
</code>
</pre>
</blockquote>
</section>
<section id="props">
<h2>Props参数</h2>
<p>左侧导航栏使用了最基本的形式:</p>
<blockquote>
<pre class="language-html"><code class="language-html"><affix>导航栏...</affix></code></pre>
</blockquote>
<p>还可以指定偏移距离:</p>
<blockquote>
<pre class="language-html"><code class="language-html"><affix :offset="50">当距离顶部50px时, 开始绝对定位...</affix></code></pre>
</blockquote>
<p>相对于窗口底部偏移:</p>
<blockquote>
<pre class="language-html"><code class="language-html"><affix type="bottom">相对于底部而言</affix></code></pre>
</blockquote>
<blockquote>
<pre class="language-js">
<code class="language-js">
props: {
// 类型(仅能为bottom 和 top)
type: {
type: String,
default: 'top',
validator (value) {
return value === 'top' || value === 'bottom'
}
},
// 偏移距离
offset: {
type: Number,
default: 0
},
// 监听间隔毫秒数 (事件节流)
delay: {
type: Number,
default: 100
},
// z-index值(当绝对定位时, z-index值)
zIndex: {
type: Number,
default: 10
}
}
</code></pre>
</blockquote>
</section>
<section id="todo">
<h2>待做事项</h2>
<blockquote>
<ul>
<li>增加 typescript 提示</li>
<li>增加单元测试</li>
<li>增加e2e测试</li>
<li>增加指定相对元素偏移target</li>
<li>增加英文文档</li>
</ul>
</blockquote>
</section>
<section id="reference">
<h2>参考链接</h2>
<ul>
<li>
<a
href="https://www.iviewui.com/components/affix"
rel="noopener noreferrer"
target="_blank"
>iview affix组件</a>
</li>
<li>
<a
href="https://vue.ant.design/components/affix-cn/"
target="_blank"
>ant design affix组件</a>
</li>
<li>
<a
href="https://github.com/eddiemf/vue-affix"
target="_blank"
>vue-affix组件</a>
</li>
<li>
<a
href="https://www.zhangxinxu.com/wordpress/2019/01/dom-quiz-27-window-scroll/"
target="_blank"
>张鑫旭-窗体滚动二三事</a>
</li>
</ul>
</section>
</easy-github-pages>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
menuList: [
{
title: '介绍',
href: 'intro'
},
{
title: '创作原因',
href: 'reason'
},
{
title: '安装',
href: 'install'
},
{
title: '使用',
href: 'usage'
},
{
title: 'Props参数',
href: 'props'
},
{
title: '待做事项',
href: 'todo'
},
{
title: '参考链接',
href: 'reference'
}
]
}
}
}
</script>