- 现在项目中创建
store文件夹,分别包括index.js、getters.js、action.js、mutations.js -
index.js中引入getters.js、action.js、mutations.js -
action.js -
getters.js在页面中获取username就是通过getUsername -
mutations.js - 在页面中获取
username - 在页面中修改
usernamethis.$store.dispatch('updateUsername', 'lily')
是不是很简单~~~