瀏覽代碼

:sparkles: creating rudimentary card component

tags/0.0.1
J 5 年之前
父節點
當前提交
334cc4e205
共有 7 個檔案被更改,包括 100 行新增2636 行删除
  1. 1
    2621
      package-lock.json
  2. 29
    2
      src/App.vue
  3. 1
    1
      src/components/HelloWorld.vue
  4. 60
    0
      src/components/card.vue
  5. 5
    5
      src/sss/index.js
  6. 2
    5
      src/sss/partials/_reset.sss
  7. 2
    2
      src/sss/partials/_typography.sss

+ 1
- 2621
package-lock.json
文件差異過大導致無法顯示
查看文件


+ 29
- 2
src/App.vue 查看文件

1
 <template lang="pug">
1
 <template lang="pug">
2
-img(alt="Vue logo" src="./assets/logo.png")
2
+.cards.f-row
3
+    card(v-for="card in cards" :card="card" @remove="remove")
3
 hello-world(msg="Hello Vue 3 + Vite")
4
 hello-world(msg="Hello Vue 3 + Vite")
4
 </template>
5
 </template>
5
 
6
 
6
-<script setup>
7
+<script>
8
+import { ref } from 'vue'
9
+
7
 import helloWorld from '@/components/HelloWorld.vue'
10
 import helloWorld from '@/components/HelloWorld.vue'
11
+import card from '@/components/card.vue'
12
+
13
+export default {
14
+    components: { card, helloWorld },
15
+    setup() {
16
+    
17
+        const cards = ref([
18
+            { name: 'jwick' },
19
+            { name: 'hwick' },
20
+            { name: 'kwick' },
21
+        ])
22
+
23
+        const remove = card => {
24
+            const i = cards.value.indexOf(card)
25
+            cards.value.splice(i, 1)
26
+            console.log(cards.value)
27
+        }
28
+
29
+        return { 
30
+            cards,
31
+            remove
32
+        }
33
+    }
34
+}
8
 </script>
35
 </script>
9
 
36
 
10
 <style lang="postcss">
37
 <style lang="postcss">

+ 1
- 1
src/components/HelloWorld.vue 查看文件

40
 api.put(state.profile).then(p => {
40
 api.put(state.profile).then(p => {
41
     state.loaded = true
41
     state.loaded = true
42
     console.log(p)
42
     console.log(p)
43
-    api.sync()
43
+    // api.sync()
44
 })
44
 })
45
 </script>
45
 </script>
46
 
46
 

+ 60
- 0
src/components/card.vue 查看文件

1
+<template lang="pug">
2
+.card
3
+    header
4
+        p {{ card.name }}
5
+
6
+    main
7
+        section
8
+            img(alt="Vue logo" style="width: 100%;" src="@/assets/logo.png")
9
+
10
+    footer
11
+        button(@click="state.count++") {{ state.count }}
12
+        button(@click="close") close
13
+
14
+</template>
15
+
16
+<script setup>
17
+import { defineProps, reactive, getCurrentInstance } from 'vue'
18
+
19
+const instance = getCurrentInstance()
20
+
21
+const props = defineProps({
22
+    msg: String,
23
+    card: Object
24
+})
25
+
26
+const state = reactive({
27
+    count: 0,
28
+    loaded: false,
29
+    profile: null
30
+})
31
+
32
+const close = e => {
33
+    instance.emit('remove', props.card)
34
+}
35
+
36
+</script>
37
+
38
+<style lang="postcss">
39
+
40
+$pad: 0.5vw
41
+
42
+.card
43
+    background-color: rebeccapurple
44
+    opacity: 0.8
45
+    width: calc($pad * 20)
46
+    height: calc($pad * 40)
47
+    border-radius: $pad
48
+    margin-bottom: -5vh
49
+    display: flex
50
+    border: 1px solid black
51
+    flex-direction: column
52
+    header, main, footer
53
+        text-align: left
54
+        padding: 0 $pad
55
+    header
56
+        padding-top: $pad
57
+    footer
58
+        padding-bottom: $pad
59
+
60
+</style>

+ 5
- 5
src/sss/index.js 查看文件

1
-import './partials/_reset.sss'
2
-import './partials/_helpers.sss'
3
-import './partials/_typography.sss'
1
+import '@/sss/partials/_helpers.sss'
2
+import '@/sss/partials/_typography.sss'
3
+import '@/sss/partials/_reset.sss'
4
 
4
 
5
-import layoutVars from './variables.sss'
6
-import themeVars from './theme.sss'
5
+import layoutVars from '@/sss/variables.sss'
6
+import themeVars from '@/sss/theme.sss'
7
 
7
 
8
 const splitVars = varsFromSSS => {
8
 const splitVars = varsFromSSS => {
9
     return varsFromSSS.split('\n').map(line => line.split(':')).reduce((vars, pair) => {
9
     return varsFromSSS.split('\n').map(line => line.split(':')).reduce((vars, pair) => {

+ 2
- 5
src/sss/partials/_reset.sss 查看文件

1
-@import '../variables.sss'
2
-@import '../theme.sss'
3
 
1
 
4
 *
2
 *
5
     margin: 0
3
     margin: 0
18
 html
16
 html
19
     cursor: default
17
     cursor: default
20
     font-family: system-ui
18
     font-family: system-ui
21
-    line-height: $ms-0
19
+    line-height: 1vh
22
     tab-size: 4
20
     tab-size: 4
23
 
21
 
24
 body
22
 body
25
     margin: 0
23
     margin: 0
26
-    font-size: $ms-1
27
-    font-family: $sans
24
+    font-size: 1em
28
 
25
 
29
 nav
26
 nav
30
     ol, ul
27
     ol, ul

+ 2
- 2
src/sss/partials/_typography.sss 查看文件

1
-@import '../variables.sss'
2
-@import '../theme.sss'
1
+import '../variables.sss'
2
+import '../theme.sss'
3
 
3
 
4
 h1
4
 h1
5
     font-size: $ms-5
5
     font-size: $ms-5

Loading…
取消
儲存