Przeglądaj źródła

Use vuex to store threads and add computed property in Index route to show threads

sbkwgh 8 lat temu
rodzic
commit
04943ef53a
3 zmienionych plików z 25 dodań i 1 usunięć
  1. 5 0
      src/components/routes/Index.vue
  2. 3 0
      src/store/index.js
  3. 17 1
      src/store/modules/index.js

+ 5 - 0
src/components/routes/Index.vue

@@ -58,6 +58,11 @@
 				selected: null,
 				categories
 			}
+		},
+		computed: {
+			threads () {
+				return this.$store.state.index.threads;
+			}
 		}
 	}
 </script>

+ 3 - 0
src/store/index.js

@@ -27,5 +27,8 @@ export default new Vuex.Store({
 		hideModal (state, modal) {
 			state.modals[modal] = false;
 		}
+	},
+	modules: {
+		index
 	}
 })

+ 17 - 1
src/store/modules/index.js

@@ -1,4 +1,20 @@
-const state = {}
+const state = {
+	threads: [
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30},
+		{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), replies: 30}
+	]
+}
 
 const getters = {}