-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["es2015-webpack"] | ||
"presets": ["es2015-webpack", "stage-2"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
<template> | ||
<div id="app"> | ||
<img src="./assets/logo.png"> | ||
<button @click='increment'>Increment +1</button> | ||
<button @click='decrement'>Decrement -1</button> | ||
<ul> | ||
<li><router-link to="/">Home</router-link></li> | ||
<li><router-link to="/" exact>Home</router-link></li> | ||
<li><router-link to="/topics">Topics</router-link></li> | ||
<li><router-link to="/display">Display</router-link></li> | ||
<li><router-link to="/about">About</router-link></li> | ||
</ul> | ||
<router-view class="view"></router-view> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions } from 'vuex' | ||
import store from './vuex/store' | ||
export default { | ||
methods: { | ||
...mapActions([ | ||
'increment', | ||
'decrement', | ||
'getTopics' | ||
]) | ||
}, | ||
store | ||
} | ||
</script> | ||
|
||
<style> | ||
body { | ||
font-family: Helvetica, sans-serif; | ||
} | ||
.router-link-active{ | ||
color: red ; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<div> | ||
<h3>Count is {{ count }}</h3> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters, mapActions } from 'vuex' | ||
export default { | ||
computed: { | ||
...mapGetters({ | ||
count: 'getCount' | ||
}) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div> | ||
<div v-for="topic in topics"> | ||
<p>{{topic.title}}</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters, mapActions } from 'vuex' | ||
export default { | ||
computed: { | ||
...mapGetters({ | ||
topics: 'getTopics' | ||
}) | ||
}, | ||
created () { | ||
this.$store.dispatch('getTopics') | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
import router from './router.js' | ||
import store from './vuex/store' | ||
|
||
const app =new Vue(Vue.util.extend({ router }, App)) | ||
const app = new Vue(Vue.util.extend({ router }, App)) | ||
export default context => { | ||
router.setInitialLocation(context.url) | ||
context.initialState = store.state | ||
return app | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import request from 'axios' | ||
|
||
export const getTopics = ({ commit, state }) => { | ||
request.get('https://cnodejs.org/api/v1/topics').then((response) => { | ||
// console.log(response) | ||
commit('TOPICS_LIST', response.data.data) | ||
}).catch((error) => { | ||
console.log(error) | ||
}) | ||
} | ||
|
||
|
||
export const increment = ({ commit }) => commit('INCREMENT') | ||
export const decrement = ({ commit }) => commit('DECREMENT') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const getTopics = state => state.topics | ||
export const getCount = state => state.count | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Vue from 'vue' | ||
import Vuex from 'vuex' | ||
import * as actions from './actions' | ||
import * as getters from './getters' | ||
|
||
Vue.use(Vuex) | ||
|
||
const defaultState = { | ||
topics: [], | ||
count: 0 | ||
} | ||
|
||
const state = typeof __INITIAL_STATE__ !== 'undefined' ? __INITIAL_STATE__ : defaultState | ||
|
||
// const mutations = { | ||
// TOPICS_LIST (state, topics) { | ||
// state.topics = topics | ||
// } | ||
// } | ||
const mutations = { | ||
TOPICS_LIST (state, topics) { | ||
state.topics = topics | ||
}, | ||
|
||
INCREMENT (state) { | ||
state.count++ | ||
}, | ||
|
||
DECREMENT (state) { | ||
state.count-- | ||
} | ||
} | ||
|
||
export default new Vuex.Store({ | ||
state, | ||
mutations, | ||
actions, | ||
getters: Object.assign({}, getters) | ||
}) |