Fun with Vuex and Router
A toy app that uses vuex to track some minor state of an app. Need to add actions to interact with a remote service, but that is going to be missing until I can get APIStar 0.4 up and running.master
parent
8d79dcb71e
commit
bd35bbeab4
@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<div class="hello">
|
||||||
|
<h1>{{ msg }}</h1>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'Central',
|
||||||
|
props: {
|
||||||
|
msg: String,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
|
<style scoped lang="scss">
|
||||||
|
h3 {
|
||||||
|
margin: 40px 0 0;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0 10px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #42b983;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,57 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="hello">
|
|
||||||
<h1>{{ msg }}</h1>
|
|
||||||
<p>
|
|
||||||
For guide and recipes on how to configure / customize this project,<br>
|
|
||||||
check out the
|
|
||||||
<a href="https://github.com/vuejs/vue-cli/tree/dev/docs" target="_blank">vue-cli documentation</a>.
|
|
||||||
</p>
|
|
||||||
<h3>Installed CLI Plugins</h3>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank">babel</a></li>
|
|
||||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank">eslint</a></li>
|
|
||||||
</ul>
|
|
||||||
<h3>Essential Links</h3>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
|
|
||||||
<li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
|
|
||||||
<li><a href="https://chat.vuejs.org" target="_blank">Community Chat</a></li>
|
|
||||||
<li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
|
|
||||||
</ul>
|
|
||||||
<h3>Ecosystem</h3>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://router.vuejs.org/en/essentials/getting-started.html" target="_blank">vue-router</a></li>
|
|
||||||
<li><a href="https://vuex.vuejs.org/en/intro.html" target="_blank">vuex</a></li>
|
|
||||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank">vue-devtools</a></li>
|
|
||||||
<li><a href="https://vue-loader.vuejs.org/en" target="_blank">vue-loader</a></li>
|
|
||||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'HelloWorld',
|
|
||||||
props: {
|
|
||||||
msg: String,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
||||||
<style scoped lang="scss">
|
|
||||||
h3 {
|
|
||||||
margin: 40px 0 0;
|
|
||||||
}
|
|
||||||
ul {
|
|
||||||
list-style-type: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
li {
|
|
||||||
display: inline-block;
|
|
||||||
margin: 0 10px;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
color: #42b983;
|
|
||||||
}
|
|
||||||
</style>
|
|
@ -1,18 +1,46 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="home">
|
<div class="home">
|
||||||
<img src="../assets/logo.png">
|
<Central :msg="msg"/>
|
||||||
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
<p @click="incrementStoredNumber"> The safely stored number: {{ safelyStoredNumber }}</p>
|
||||||
|
<input type="text" name="number" v-model="number" value="">
|
||||||
|
<button @click="setStoredNumber" type="button" name="button">Set the stored number</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// @ is an alias to /src
|
// @ is an alias to /src
|
||||||
import HelloWorld from '@/components/HelloWorld.vue';
|
import Central from '@/components/Central.vue';
|
||||||
|
import { mapGetters, mapMutations } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'home',
|
name: 'home',
|
||||||
|
data() {
|
||||||
|
return { number: 0 }
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
HelloWorld,
|
Central,
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapGetters([
|
||||||
|
// Mounts the msg getter to the she scope of this components `msg`
|
||||||
|
'msg',
|
||||||
|
// 'safelyStoredNumber'
|
||||||
|
]),
|
||||||
|
// Alternatively we could do this instead to access the getters
|
||||||
|
safelyStoredNumber() {
|
||||||
|
return this.$store.getters.safelyStoredNumber
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
...mapMutations([
|
||||||
|
'incrementStoredNumber'
|
||||||
|
]),
|
||||||
|
// Alternatively we could also do This
|
||||||
|
setStoredNumber() {
|
||||||
|
this.$store.commit('setStoredNumber', this.number)
|
||||||
|
this.number = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue