Vue学习- 使用登录用户的信息
- App.vue
- 登录数据赋值
- list.vue
- 获取登录用户信息
- import { mapState } from 'vuex';
- computed: { ...mapState(['account']) },
- computed内 定义对应信息
- userProdIDs() { return this.account?.ProdIDs || []; }
- 使用computed定义的字段
- this.userProdIDs
- 两个结果集的交集
- _this.products = ret.data.filter(product => {
- return this.userProdIDs.includes(product.ID);
- });
- 方法传参
-
params: {
-
...this.page.search,
-
ProdIDs: this.userProdIDs
-
},
-
AjaxPost('/admin/survey/list', this.page.search, (ret) => {
-
- 保留所有产品数据,但标记哪些是可以选中的
- _this.products = ret.data;
-
_this.products = ret.data.map(product => ({
-
...product,
-
disabled: !_this.userProdIDs.includes(product.ID) // 如果不在用户权限内则禁用
-
}));
- 获取登录用户信息
浙公网安备 33010602011771号