一、store中定义的常量在页面中使用
const state = {
appName: 'admin'
}
export default state
const state = {
userName: 'sun'
}
const mutations = {
}
const actions = {
}
export default {
state,
mutations,
actions
}
<template>
<div>
<!--v-model指令为双向绑定-->
<!--<a-input v-model="inputValue"/>-->
<a-input @input="handleInput"/>
<!--<a-input :value="inputValue", @input="handleInput"/>-->
<!--<p>{{inputValue}}</p>-->
<a-show :content="inputValue"/>
<p>{{appName}}</p>
<p>{{userName}}</p>
</div>
</template>
<script>
import AInput from '_c/AInput.vue'
import AShow from '_c/AShow.vue'
export default {
name: "store",
data() {
return {
inputValue: ''
}
},
computed: {
appName () {
return this.$store.state.appName
},
userName () {
return this.$store.state.user.userName
}
},
components: {
AInput,
AShow
},
methods: {
handleInput (value) {
this.inputValue = value
}
}
}
</script>
<style scoped>
</style>