以userId为例:
1.首先在store文件夹中找到存储数据的地方。比如userId,就存放在store/user.js中
2.打开user.js,定义一个userId,用于存储用户id,SET_USERID是将userId存入state中,方便后续使用
3.找到store/getter.js,这个getter.js文件是用来获取state中的数据的,这样写是为了方便使用,直接在页面中使用this.$store.getters.userId就可以获取到userId。
4.之后就可以在其他组件中获取userId.
this.userId = this.$store.state.user.userId;