当前位置:网站首页>pinia 模块划分
pinia 模块划分
2022-07-06 16:25:00 【梁云亮】
pinia的模块划分是通过js命名来划分的。
示例:
第一步:拆分store文件
- store/index.ts
import {
createPinia } from "pinia"
const store = createPinia()
export default store
- store/user.ts
import {
defineStore} from "pinia"
export const useUserStore = defineStore({
//js命名
id: "user",
state: () => {
return {
name: '张三',
age: 18
}
}
})
- store/order.ts
import {
defineStore} from "pinia"
export const useOrderStore = defineStore({
//js命名
id: "order",
state: () => {
return {
orderList: [{
id: 1001, total: 6666}, {
id: 1002, total: 8888}, {
id: 1003, total: 9999}]
}
}
})
第二步:vue
- User.vue
<template>
User:{
{ name }} == {
{ age }}
</template>
<script setup lang="ts"> import {
storeToRefs} from "pinia" import {
useUserStore} from "@/store/module/user" const userStore = useUserStore() const {
name, age} = storeToRefs(userStore) </script>
- Order.vue
<template>
order <br>
{
{order}}
</template>
<script setup lang='ts'> import {
storeToRefs} from "pinia" import {
useOrderStore} from "@/store/module/order" const orderStore = useOrderStore() const order = storeToRefs(orderStore) </script>
边栏推荐
- Unity color palette | color palette | stepless color change function
- One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
- Gradle知識概括
- 每日刷题记录 (十五)
- ArrayExpress数据库里的细胞只有两个txt是不是只能根据Line到ENA下载测序跑矩阵?
- If the request URL contains jsessionid, the solution
- Entropy information entropy cross entropy
- 三句话简要介绍子网掩码
- How to implement Lua entry of API gateway
- 求帮助xampp做sqlilab是一片黑
猜你喜欢

Basic chart interpretation of "Oriental selection" hot out of circle data

Gold three silver four, don't change jobs
Implementation steps of mysql start log in docker

STM32通过串口进入和唤醒停止模式

Experiment 4: installing packages from Gui

I've been laid off, and I'll lose money for everything. The days when I once made a monthly salary of 20000 are not coming back

If the request URL contains jsessionid, the solution

Cas d'essai fonctionnel universel de l'application

Knowledge * review

11 preparations for Web3 and Decentralization for traditional enterprises
随机推荐
Gradle知識概括
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
Basic chart interpretation of "Oriental selection" hot out of circle data
服务器SMP、NUMA、MPP体系学习笔记。
Example code of MySQL split string as query condition
What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
新手问个问题,我现在是单机部署的,提交了一个sql job运行正常,如果我重启了服务job就没了又得
Laravel8 uses passport authentication to log in and generate a token
Restoration analysis of protobuf protocol of bullet screen in station B
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code
亚朵三顾 IPO
JDBC programming of MySQL database
The best sister won the big factory offer of 8 test posts at one go, which made me very proud
求帮助xampp做sqlilab是一片黑
Local deployment Zeppelin 0.10.1
Wu Enda 2022 machine learning course evaluation is coming!
Oracle对表进行的常用修改命令
Cloud native (32) | kubernetes introduction to platform storage system
自动化测试工具Katalon(Web)测试操作说明
[system analyst's road] Chapter 7 double disk system design (service-oriented development method)