<template> <div id="login"> <c-header></c-header> <c-form></c-form> <p class="content-block"><a href="javascript:;" rel="external nofollow" rel="external nofollow" @click=showState class="button button-fill button-success">登录</a></p> </div> </template>
import Vue from 'vue'
import Vuex from 'vuex'
// 首先声明一个状态 state
const state = {
msg: ''
}
// 然后给 actions 注册一个事件处理函数,当这个函数被触发时,将状态提交到 mutaions中处理
const actions = {
saveName({commit}, msg) {
commit('saveMsg', msg) // 提交到mutations中处理
}
}
// 更新状态
const mutations = {
saveMsg(state, msg) {
state.msg = msg;
}
}
// 获取状态信息
const getter = {
showState(state) {
console.log(state.msg)
}
}
// 下面这个相当关键了,所有模块,记住是所有,注册才能使用
export default new Vuex.Store{
state,
getter,
mutations,
actions
}
<template>
<div>
<input type="text" @blur=saveName(username) v-model="username" placeholder="Your name">
</div>
</template>
<script type="text/javascript">
// 引入mapActions,很重要
import { mapActions } from 'vuex'
export default {
data() {
return {
username:'',
password: ''
}
},
methods: {
...mapActions({
// 在input 的blur 事件中触发回调,并将输入值作为参数返回到store中
saveName: 'saveName'
})
}
}
</script>
<template>
<div id="login">
<c-header></c-header>
<c-form></c-form>
<p class="content-block"><a href="javascript:;" rel="external nofollow" rel="external nofollow" @click=showState class="button button-fill button-success">登录</a></p>
</div>
</template>
<script>
// 引入mapGtters,很重要
import { mapGetters } from 'vuex'
export default {
methods: {
...mapGetters([
// 在store.js 中注册的getters
'showState'
])
},
components: {
"c-form": require('../components/form.vue'),
"c-header": require('../components/header.vue')
}
}
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有