Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Created June 12, 2017 09:10
Show Gist options
  • Save gearmobile/a90d220f99bfc97e06ebd602dbfc5166 to your computer and use it in GitHub Desktop.
Save gearmobile/a90d220f99bfc97e06ebd602dbfc5166 to your computer and use it in GitHub Desktop.
App.vue
// ----------------------
<template lang="pug">
#app
img( src="./assets/logo.png" )
//- img( :src="pathImage" )
hello
</template>
<script>
import Hello from './components/Hello'
import { mapGetters } from 'vuex'
export default {
name: 'app',
components: {
Hello
},
computed: {
...mapGetters({
pathImage: 'getImage'
})
}
}
</script>
// -----------------------------
store/index.js
// -----------------------------
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
bool: true,
array: ['bar'],
imagePath: './assets/logo.png'
}
const mutations = {
'SET_BOOL' (state, payload) {
state.bool = payload
},
'SET_ARRAY' (state, payload) {
state.array = payload
}
}
const actions = {
setBool ({ commit }, payload) {
commit('SET_BOOL', payload)
},
setArray ({ commit }, payload) {
commit('SET_ARRAY', payload)
}
}
const getters = {
getBool (state) {
return state.bool
},
getArray (state) {
return state.array
},
getImage (state) {
return state.imagePath
}
}
const store = new Vuex.Store({
state,
mutations,
actions,
getters
})
export default store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment