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

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - smil、梵音

TortoiseGit 的安装与汉化 安装虚拟机+ ubuntu24.04 系统 联想小新安装 ubuntu24.04 双系统 | 安装乌版图系统 | windows安装 ubuntu24.04 双系统 利用faststone capture制作gif动图 Sublime Text 常用编辑快捷键速查表 vscode 中的 css 样式代码不显示折叠图标的解决方法 IDEA中git的Cherry-Pick的可视化使用(个人总结) IDEA中git的Cherry-Pick的使用 IDEA中如何实现git的cherry-pick可视化操作? Windows11添加系统环境变量 VS Code——Live Server的简介、安装与使用 vscode使用region折叠任意想折叠的代码块 我本地分支代码推送到远程的另一个分支,怎么操作? idea中打开多文件编辑器换行展示 本地代码强制覆盖远程代码,本地代码强制和远程某一个分支保持一致,再覆盖远程代码 css头部固定,内容区域高度自适应剩余的屏幕高度,内容区域过多显示竖向滚动条 flex为1的元素宽度自适应的同时,文本太长的时候显示省略号 idea中项目文件目录消失如何解决 vue3插入图片 vue3使用构建工具时,关于本地图片的引用 vue3 中父组件调用子组件的方法,子组件是不是必须暴露方法 如何改变type="checkbox"的input复选框的样式 vue3中非父子组件、非祖先-后代组件之间传递方法 解决 IntelliJ IDEA 中项目右键没有 Git 菜单的问题 关于 ref 为 DOM 元素或子组件实例动态创建引用的总结 Git 合并时出现 Please enter a commit message to explain why this merge is necessary 问题解决 拉取远程其他分支的最新代码 - smil、梵音
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 的值了。