Skip to content

Commit 3c82dff

Browse files
committed
fix: fix chunk data
1 parent 0aa91b0 commit 3c82dff

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed
File renamed without changes.

package-lock.json

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "vue-cli-service lint"
1010
},
1111
"dependencies": {
12+
"axios": "^0.24.0",
1213
"core-js": "^3.6.5",
1314
"register-service-worker": "^1.7.1",
1415
"teenyicons": "^0.4.1",

src/App.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,40 @@
44
<router-link to="/keyword">Keyword</router-link> |
55
<router-link to="/search">Search</router-link>
66
</div>
7-
<router-view :jobData="totalJobData"/>
7+
<router-view :chunkData="chunkJobData" :jobData="totalJobData" :loadData="loadData"/>
88
</template>
99

1010
<script>
11-
import ccJob from './final.json'
11+
// import ccJob from './final.json'
12+
import axios from 'axios'
13+
// import { mapState, mapActions } from 'vuex'
14+
1215
export default {
1316
data () {
1417
return {
15-
totalJobData: ccJob
18+
totalJobData: [], // 改用 vuex
19+
keywordChunk: 0
20+
}
21+
},
22+
mounted () {
23+
this.getTotalJobData()
24+
},
25+
computed: {
26+
chunkJobData () {
27+
return this.totalJobData.slice(0, this.keywordChunk + 3)
28+
}
29+
// ...mapState(['dataArray'])
30+
},
31+
methods: {
32+
// 改用 vuex
33+
getTotalJobData () {
34+
axios.get('https://raw.githubusercontent.com/linooohon/creative-coding-jobs-update/data/final.json').then((res) => {
35+
this.totalJobData = res.data
36+
})
37+
},
38+
// ...mapActions(['getTotalJobData']),
39+
loadData () {
40+
this.keywordChunk += 1
1641
}
1742
}
1843
}

src/store/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { createStore } from 'vuex'
2+
import axios from 'axios'
23

4+
// not use right now
35
export default createStore({
46
state: {
7+
dataArray: []
58
},
69
mutations: {
10+
assignToData (state, payload) {
11+
state.dataArray = payload
12+
}
713
},
814
actions: {
15+
async getTotalJobData (context) {
16+
const data = await axios.get('https://raw.githubusercontent.com/linooohon/creative-coding-jobs-update/main/src/final.json')
17+
context.commit('assignToData', data.data)
18+
}
919
},
1020
modules: {
1121
}

src/views/Dashboard.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="jobCard_wrapper">
3-
<div v-for="(jobItem, index) in jobData" :key="index">
3+
<div v-for="(jobItem, index) in chunkData" :key="index">
44
<div v-for="item in Object.entries(jobItem)" :key="item[0]">
55
<div class="jobCard_keyword">{{ item[0] }}</div>
66
<div class="jobCard_platform">
@@ -32,6 +32,7 @@
3232
</div>
3333
</div>
3434
</div>
35+
<button @click="loadData">More</button>
3536
</template>
3637

3738
<script>
@@ -47,7 +48,7 @@ export default {
4748
indeed: 'Indeed'
4849
}
4950
},
50-
props: ['jobData'],
51+
props: ['chunkData', 'loadData'],
5152
components: {
5253
JobCard
5354
}

0 commit comments

Comments
 (0)