当前位置:网站首页>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>
边栏推荐
- Win11怎么恢复传统右键菜单?Win11右键改回传统模式的方法
- leetcode:236. 二叉树的最近公共祖先
- Can async i/o be implemented by UDF operator and then called by SQL API? At present, it seems that only datastre can be seen
- Server SMP, NUMA, MPP system learning notes.
- Common modification commands of Oracle for tables
- The best sister won the big factory offer of 8 test posts at one go, which made me very proud
- flinksql select id ,count(*) from a group by id .
- 每日刷题记录 (十五)
- 基础图表解读“东方甄选”爆火出圈数据
- How can Oracle CDC deserialize with jsondebeziumdeserializationschema
猜你喜欢
传统企业要为 Web3 和去中心化做的 11 个准备
Gradle knowledge generalization
With the help of this treasure artifact, I became the whole stack
Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming
Knowledge * review
11 preparations for Web3 and Decentralization for traditional enterprises
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
js對JSON數組的增删改查
JS addition, deletion, modification and query of JSON array
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
随机推荐
There are only two TXT cells in the ArrayExpress database. Can you only download the sequencing run matrix from line to ENA?
Résumé des connaissances de gradle
【无人机】多无人协同任务分配程序平台含Matlab代码
MySQL implementation of field segmentation from one line to multiple lines of example code
Cloud native (32) | kubernetes introduction to platform storage system
Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming
浅谈现在的弊端与未来的发展
不要再说微服务可以解决一切问题了
flinksql select id ,count(*) from a group by id .
The method of reinstalling win10 system is as simple as that
服务器SMP、NUMA、MPP体系学习笔记。
AVL树到底是什么?
Example code of MySQL split string as query condition
同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Automatically update selenium driver chromedriver
STM32 enters and wakes up the stop mode through the serial port
Stop saying that microservices can solve all problems
okcc呼叫中心的订单管理时怎么样的
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial