当前位置:网站首页>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>
边栏推荐
- There are only two TXT cells in the ArrayExpress database. Can you only download the sequencing run matrix from line to ENA?
- Penetration test --- database security: detailed explanation of SQL injection into database principle
- Let me ask you if there are any documents or cases of flynk SQL generation jobs. I know that flynk cli can create tables and specify items
- Competition between public and private chains in data privacy and throughput
- What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
- Can online reload system software be used safely? Test use experience to share with you
- flinksql select id ,count(*) from a group by id .
- 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
- The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method
- Talking about the current malpractice and future development
猜你喜欢

The programmer refused the offer because of low salary, HR became angry and netizens exploded

koa2对Json数组增删改查

MySQL connected vscode successfully, but this error is reported

The method of reinstalling win10 system is as simple as that

传统企业要为 Web3 和去中心化做的 11 个准备

Wu Enda 2022 machine learning course evaluation is coming!

Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming

基于SSM框架实现的房屋租赁管理系统

Talking about the current malpractice and future development

STM32通过串口进入和唤醒停止模式
随机推荐
Server SMP, NUMA, MPP system learning notes.
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
Laravel8 uses passport authentication to log in and generate a token
【无人机】多无人协同任务分配程序平台含Matlab代码
氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
Leetcode problem solving - 889 Construct binary tree according to preorder and postorder traversal
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
STM32 enters and wakes up the stop mode through the serial port
基于SSM框架实现的房屋租赁管理系统
MATLIB reads data from excel table and draws function image
Eureka Client启动后就关闭 Unregistering application xxx with eureka with status DOWN
Entropy information entropy cross entropy
One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
How does crmeb mall system help marketing?
Yaduo Sangu IPO
Detailed explanation of regular expression (regexp) in MySQL
MATLIB从excel表中读取数据并画出函数图像
传统企业要为 Web3 和去中心化做的 11 个准备
App general function test cases
Close unregistering application XXX with Eureka with status down after Eureka client starts