From 1824b5578218479d6fac2b568dfc44d2505b3f85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= <438123081@qq.com>
Date: Tue, 6 Aug 2024 10:20:56 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E7=8A=B6?=
=?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86=E5=99=A8pinia?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 2 ++
main.js | 26 ++++++--------
package-lock.json | 81 +++++++++++++++++++++++++++++++++++++++++++
package.json | 6 ++++
pages/index/index.vue | 27 ++++++++++-----
stores/user.js | 17 +++++++++
6 files changed, 135 insertions(+), 24 deletions(-)
create mode 100644 package-lock.json
create mode 100644 package.json
create mode 100644 stores/user.js
diff --git a/.gitignore b/.gitignore
index 8ba616d..f5e1955 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
.idea
.hbuilderx
.DS_Store
+unpackage
+node_modules
diff --git a/main.js b/main.js
index c1caf36..718ba9b 100644
--- a/main.js
+++ b/main.js
@@ -1,22 +1,18 @@
import App from './App'
-
-// #ifndef VUE3
-import Vue from 'vue'
-import './uni.promisify.adaptor'
-Vue.config.productionTip = false
-App.mpType = 'app'
-const app = new Vue({
- ...App
-})
-app.$mount()
-// #endif
-
-// #ifdef VUE3
+import * as Pinia from 'pinia'
import { createSSRApp } from 'vue'
+import { createUnistorage } from 'pinia-plugin-unistorage'
+
export function createApp() {
const app = createSSRApp(App)
+
+ // pinia数据持久化
+ const store = Pinia.createPinia()
+ store.use(createUnistorage())
+ app.use(store)
+
return {
- app
+ app,
+ Pinia
}
}
-// #endif
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..770e7e0
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,81 @@
+{
+ "name": "wx-starlock",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "dependencies": {
+ "pinia": "^2.2.0",
+ "pinia-plugin-unistorage": "^0.1.2"
+ }
+ },
+ "node_modules/@vue/devtools-api": {
+ "version": "6.6.3",
+ "license": "MIT"
+ },
+ "node_modules/pinia": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.2.0.tgz",
+ "integrity": "sha512-iPrIh26GMqfpUlMOGyxuDowGmYousTecbTHFwT0xZ1zJvh23oQ+Cj99ZoPQA1TnUPhU6AuRPv6/drkTCJ0VHQA==",
+ "license": "MIT",
+ "dependencies": {
+ "@vue/devtools-api": "^6.6.3",
+ "vue-demi": "^0.14.8"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/posva"
+ },
+ "peerDependencies": {
+ "@vue/composition-api": "^1.4.0",
+ "typescript": ">=4.4.4",
+ "vue": "^2.6.14 || ^3.3.0"
+ },
+ "peerDependenciesMeta": {
+ "@vue/composition-api": {
+ "optional": true
+ },
+ "typescript": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pinia-plugin-unistorage": {
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/pinia-plugin-unistorage/-/pinia-plugin-unistorage-0.1.2.tgz",
+ "integrity": "sha512-WXit2cGnm5rG6CDTcLSLehNWhyJS/Yq7WEeeXAapZbCnqoPJxlszqg7rT8S+OP47az0h5nlajGo+LuyMxUQ2uw==",
+ "license": "MIT"
+ },
+ "node_modules/vue": {
+ "version": "2.6.14",
+ "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.14.tgz",
+ "integrity": "sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ==",
+ "deprecated": "Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details.",
+ "license": "MIT",
+ "peer": true
+ },
+ "node_modules/vue-demi": {
+ "version": "0.14.10",
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "vue-demi-fix": "bin/vue-demi-fix.js",
+ "vue-demi-switch": "bin/vue-demi-switch.js"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/antfu"
+ },
+ "peerDependencies": {
+ "@vue/composition-api": "^1.0.0-rc.1",
+ "vue": "^3.0.0-0 || ^2.6.0"
+ },
+ "peerDependenciesMeta": {
+ "@vue/composition-api": {
+ "optional": true
+ }
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..14be6cb
--- /dev/null
+++ b/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "pinia": "^2.2.0",
+ "pinia-plugin-unistorage": "^0.1.2"
+ }
+}
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 4ca2b92..366e1fc 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -2,23 +2,35 @@
- {{title}}
+ {{title}}{{userInfo.name}}
@@ -34,11 +46,8 @@
.logo {
height: 200rpx;
width: 200rpx;
- margin-top: 200rpx;
- margin-left: auto;
- margin-right: auto;
- margin-bottom: 50rpx;
- }
+ margin: 200rpx auto 50rpx;
+ }
.text-area {
display: flex;
@@ -49,4 +58,4 @@
font-size: 36rpx;
color: #8f8f94;
}
-
+
diff --git a/stores/user.js b/stores/user.js
new file mode 100644
index 0000000..a431d0f
--- /dev/null
+++ b/stores/user.js
@@ -0,0 +1,17 @@
+/**
+ * @description 用户信息数据持久化
+ */
+import { defineStore } from 'pinia'
+
+export const useUserStore = defineStore('user', {
+ state() {
+ return {
+ userInfo: {}
+ }
+ },
+ actions: {
+ updateUserInfo(data) {
+ this.userInfo = data
+ }
+ }
+})