惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
J
Java Code Geeks
S
SegmentFault 最新的问题
L
LangChain Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
H
Help Net Security
阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
N
Netflix TechBlog - Medium
A
About on SuperTechFans
博客园 - 叶小钗
美团技术团队
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net

博客园 - smil、梵音

css渐变边框的实现 C primer Plus 第六版第4章节复习题5记录 C语言第4章末尾程序找错记录 css 的z-index的层级问题 由webai项目的 AI工作台 项目有感记录 C语言标准(C89/C90)中的32个关键字全列表 Windows 系统的 vscode 通过 Remote-SSH 连接虚拟机的 Ubuntu 系统运行 C 语言的代码 Windows 系统 vscode Remote-SSH 远程连接虚拟机里面的Ubuntu系统的失败处理 Ubuntu虚拟机里安装了SSH,开启SSH服务的时候报错 VS Code的Remote - SSH功能 Ubuntu系统里面安装 g++ ,sudo apt update 的含义 C语言是不是必须得通过gcc编译成可执行的程序? c语言用gcc编译过后,执行 ./hello.c 报错 ./hello.c: 权限不够 windows系统的虚拟机里面的Ubuntu系统安装VMware Tools Ubuntu的应用中心搜索 vscode 的时候,筛选条件为Snap包、debian包是什么意思,如何安装vscode Ubuntu系统是否就是Linux系统,安装软件和Windows系统有何区别 Ubuntu系统里面vscode运行C语言的第一个 Hello World 程序 vscode 中安装C/C++相关的插件 Ubuntu 安装一个轻量级的中文输入法Fcitx5 Ubuntu安装百度网盘 Ubuntu系统里面安装vscode 乌版图系统截屏快捷键 Ubuntu 系统里面运行C++ TortoiseGit 的安装与汉化 安装虚拟机+ ubuntu24.04 系统 联想小新安装 ubuntu24.04 双系统 | 安装乌版图系统 | windows安装 ubuntu24.04 双系统 利用faststone capture制作gif动图 Sublime Text 常用编辑快捷键速查表 vscode 中的 css 样式代码不显示折叠图标的解决方法 IDEA中git的Cherry-Pick的可视化使用(个人总结) IDEA中git的Cherry-Pick的使用
vue3中 pinia 的运用
smil、梵音 · 2025-10-11 · via 博客园 - smil、梵音

1、在 store 文件夹中定义相关的 js 文件

图片

pptWhiteList.js 文件的内容(代码内容为:登录用户是否是白名单用户,在其他文件中要用到此数据):

import { defineStore } from "pinia";
import aiApi from "../modules/index";
import { storageUtils } from "/@common/usedPackages/index.js";

export const pptWhiteListStore = defineStore("whiteListStore", {
  // 广告平台数据
  state: () => ({
    whiteListVal: 10, // 默认10, 非白名单,走厂商 ; 11 为白名单,走新阿里流程
  }),
  getters: {},
  actions: {
    async getWhiteListData() {
      const params = {
        userId: storageUtils.local.get("login_tokenInfo").userDomainId,
        sourceChannel: storageUtils.session.get("clientId"),
      };
      const res = await aiApi.getWhitelistInfo(params);
      if (res.success && res.data) {
        this.whiteListVal = res.data.aipptSupplier;
        // console.warn("store 获取白名单结果为---", this.whiteListVal);
      }
    },
  },
});

2、在其他文件中引用,例如在demo.vue 中引用。

2.1 方法一,在vue3中运用

先引入 

import { pptWhiteListStore } from "../store/pptWhiteList.js";

定义

const whiteListStore = pptWhiteListStore();

在代码中运用,判断白名单数值

console.log("测试的获取的白名单的信息值 ---", whiteListStore.whiteListVal);

2.2 在vue2中运用

引入

import { pptWhiteListStore } from "../../store/pptWhiteList.js";

在 computed 中定义

computed: {
    whiteListVal() {
        return pptWhiteListStore().whiteListVal;
    },
}

然后就可以直接运用 whiteListVal 的值了。