当前位置:网站首页>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>
边栏推荐
- Cloud native (32) | kubernetes introduction to platform storage system
- Local deployment Zeppelin 0.10.1
- app通用功能測試用例
- With the help of this treasure artifact, I became the whole stack
- 请问oracle-cdc用JsonDebeziumDeserializationSchema反序列化
- Koa2 addition, deletion, modification and query of JSON array
- AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
- JS import excel & Export Excel
- Please help xampp to do sqlilab is a black
- 基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
猜你喜欢
【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码
服务器SMP、NUMA、MPP体系学习笔记。
The problem of ASP reading Oracle Database
基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
自动化测试工具Katalon(Web)测试操作说明
Koa2 addition, deletion, modification and query of JSON array
吴恩达2022机器学习课程评测来了!
人均瑞数系列,瑞数 4 代 JS 逆向分析
浅谈现在的弊端与未来的发展
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
随机推荐
Win11怎么恢复传统右键菜单?Win11右键改回传统模式的方法
Interface joint debugging test script optimization v4.0
MATLIB reads data from excel table and draws function image
Today, I met a senior test developer from Tencent and saw the ceiling of the foundation
Wind chime card issuing network source code latest version - commercially available
今日睡眠质量记录78分
Compile logisim
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Experiment 5: common automation libraries
亚朵三顾 IPO
求帮助xampp做sqlilab是一片黑
Stop saying that microservices can solve all problems
Matplotlib draws a histogram and adds values to the graph
Scholar doctor hahaha
Example code of MySQL split string as query condition
AI金榜题名时,MLPerf榜单的份量究竟有多重?
[system analyst's road] Chapter 7 double disk system design (service-oriented development method)
js對JSON數組的增删改查
The programmer said, "I'm 36 years old, and I don't want to be rolled, let alone cut."
(LeetCode)两数之和