当前位置:网站首页>Pinia module division
Pinia module division
2022-07-06 23:52:00 【Liang Yunliang】
pinia The module division of is through js Divided by naming .
Example :
First step : Split store file
- 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 name
id: "user",
state: () => {
return {
name: ' Zhang San ',
age: 18
}
}
})
- store/order.ts
import {
defineStore} from "pinia"
export const useOrderStore = defineStore({
//js name
id: "order",
state: () => {
return {
orderList: [{
id: 1001, total: 6666}, {
id: 1002, total: 8888}, {
id: 1003, total: 9999}]
}
}
})
The second step :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>
边栏推荐
- How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
- The largest single investment in the history of Dachen was IPO today
- PostgreSQL高可用之repmgr(1主2从+1witness)+Pgpool-II实现主从切换+读写分离
- [212] what are three methods for PHP to send post requests
- MVC and MVVM
- A novice asks a question. I am now deployed on a single machine. I submitted an SQL job and it runs normally. If I restart the service job, it will disappear and I will have to
- Unity color palette | color palette | stepless color change function
- Summary of three methods for MySQL to view table structure
- One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
- Gold three silver four, don't change jobs
猜你喜欢
How much does the mlperf list weigh when AI is named?
Interface joint debugging test script optimization v4.0
Master binary tree in one article
App general function test cases
人均瑞数系列,瑞数 4 代 JS 逆向分析
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
JDBC programming of MySQL database
AVL树到底是什么?
Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
随机推荐
Unity color palette | color palette | stepless color change function
The programmer refused the offer because of low salary, HR became angry and netizens exploded
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
okcc呼叫中心的订单管理时怎么样的
每日刷题记录 (十五)
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code
Common modification commands of Oracle for tables
AVL树到底是什么?
B 站弹幕 protobuf 协议还原分析
How does crmeb mall system help marketing?
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
matplotlib画柱状图并添加数值到图中
openresty ngx_lua子请求
Compile logisim
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
Summary of three methods for MySQL to view table structure
使用yum来安装PostgreSQL13.3数据库
Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
设计一个抢红包系统
MySQL implementation of field segmentation from one line to multiple lines of example code