質問編集履歴
1
AtomButtonについての[補足]を追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -60,6 +60,96 @@
|
|
60
60
|
```
|
61
61
|
のようなv-lazy-imageを使用した画像があります。
|
62
62
|
|
63
|
+
[補足]AtomButtonはリンクボタンのコンポーネントです。
|
64
|
+
```Vue
|
65
|
+
<template>
|
66
|
+
<atom-link
|
67
|
+
:to="to"
|
68
|
+
:tag="tag"
|
69
|
+
class="button"
|
70
|
+
:class="classObject">
|
71
|
+
<span>
|
72
|
+
<slot />
|
73
|
+
</span>
|
74
|
+
</atom-link>
|
75
|
+
</template>
|
76
|
+
|
77
|
+
<script>
|
78
|
+
import Link from '@/components/atoms/Link'
|
79
|
+
export default {
|
80
|
+
name: 'AtomButton',
|
81
|
+
components: {
|
82
|
+
'atom-link': Link
|
83
|
+
},
|
84
|
+
props: {
|
85
|
+
to: {
|
86
|
+
type: String,
|
87
|
+
default: null
|
88
|
+
},
|
89
|
+
tag: {
|
90
|
+
type: String,
|
91
|
+
default: null
|
92
|
+
},
|
93
|
+
classObject: {
|
94
|
+
type: [String, Array, Object],
|
95
|
+
default: null
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
</script>
|
100
|
+
```
|
101
|
+
ここで使っているコンポーネントLinkの中身は下記の通りです。
|
102
|
+
```Vue
|
103
|
+
<template>
|
104
|
+
<component
|
105
|
+
:is="element"
|
106
|
+
v-bind="{ [attribute]: to }">
|
107
|
+
<slot />
|
108
|
+
</component>
|
109
|
+
</template>
|
110
|
+
|
111
|
+
<script>
|
112
|
+
export default {
|
113
|
+
name: 'Link',
|
114
|
+
props: {
|
115
|
+
to: {
|
116
|
+
type: String,
|
117
|
+
default: null
|
118
|
+
},
|
119
|
+
tag: {
|
120
|
+
type: String,
|
121
|
+
default: null
|
122
|
+
}
|
123
|
+
},
|
124
|
+
data: () => ({
|
125
|
+
element: 'div',
|
126
|
+
attribute: null
|
127
|
+
}),
|
128
|
+
mounted () {
|
129
|
+
this.element = this.checkElement()
|
130
|
+
this.attribute = this.checkAttribute()
|
131
|
+
},
|
132
|
+
methods: {
|
133
|
+
checkElement () {
|
134
|
+
if (this.tag) return this.tag
|
135
|
+
if (!this.to) return 'div'
|
136
|
+
if (this.to.startsWith('http')) return 'a'
|
137
|
+
if (this.to.startsWith('/static') || this.to.startsWith('/assets')) return 'a'
|
138
|
+
return 'router-link'
|
139
|
+
},
|
140
|
+
checkAttribute () {
|
141
|
+
if (this.element === 'a') return 'href'
|
142
|
+
if (this.element === 'router-link') return 'to'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
</script>
|
147
|
+
|
148
|
+
<style lang="scss" scoped>
|
149
|
+
</style>
|
150
|
+
|
151
|
+
```
|
152
|
+
|
63
153
|
### 試したこと
|
64
154
|
|
65
155
|
調べているとそもそも画像遅延読み込みとスムーズスクロールの相性が悪いということはなんとなくわかりました。
|