整合 pinia + 本地存储
This commit is contained in:
parent
d06eb120e3
commit
52848a1e8d
@ -58,7 +58,10 @@
|
|||||||
"@dcloudio/uni-mp-xhs": "3.0.0-4020920240930001",
|
"@dcloudio/uni-mp-xhs": "3.0.0-4020920240930001",
|
||||||
"@dcloudio/uni-quickapp-webview": "3.0.0-4020920240930001",
|
"@dcloudio/uni-quickapp-webview": "3.0.0-4020920240930001",
|
||||||
"@dcloudio/uni-ui": "^1.5.6",
|
"@dcloudio/uni-ui": "^1.5.6",
|
||||||
|
"destr": "^2.0.3",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
|
"pinia": "^2.2.4",
|
||||||
|
"pinia-plugin-persistedstate": "^3.2.1",
|
||||||
"vue": "^3.4.21",
|
"vue": "^3.4.21",
|
||||||
"vue-i18n": "^9.1.9"
|
"vue-i18n": "^9.1.9"
|
||||||
},
|
},
|
||||||
|
712
pnpm-lock.yaml
712
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@
|
|||||||
import App from './App'
|
import App from './App'
|
||||||
|
|
||||||
|
import pinia from './stores'
|
||||||
|
|
||||||
// #ifndef VUE3
|
// #ifndef VUE3
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import './uni.promisify.adaptor'
|
import './uni.promisify.adaptor'
|
||||||
@ -15,8 +17,9 @@ app.$mount()
|
|||||||
import { createSSRApp } from 'vue'
|
import { createSSRApp } from 'vue'
|
||||||
export function createApp() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App)
|
const app = createSSRApp(App)
|
||||||
|
app.use(pinia)
|
||||||
return {
|
return {
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
23
src/pages/index/components/category-item/index.vue
Normal file
23
src/pages/index/components/category-item/index.vue
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
src: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view style="text-align:center;padding:5px">
|
||||||
|
<image :src="props.src" mode="widthFix" style="width: 100%; height: 100%"/>
|
||||||
|
<text>
|
||||||
|
{{ props.title }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -7,12 +7,27 @@
|
|||||||
paddingTop: statusBarHeight + 'px',
|
paddingTop: statusBarHeight + 'px',
|
||||||
paddingRight: capsuleWidth + 'px',
|
paddingRight: capsuleWidth + 'px',
|
||||||
}">
|
}">
|
||||||
|
|
||||||
<uni-search-bar v-model="search.keyword" bgColor="#EEEEEE" placeholder="请输入搜索内容" @confirm="searchKeyword" cancelButton="none"></uni-search-bar>
|
<uni-search-bar v-model="search.keyword" bgColor="#EEEEEE" placeholder="请输入搜索内容" @confirm="searchKeyword" cancelButton="none"></uni-search-bar>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<swiper indicator-dots circular :autoplay="false" class="banner">
|
<swiper indicator-dots circular :autoplay="false" class="banner">
|
||||||
|
<swiper-item>
|
||||||
|
<view style="display: grid;grid-template-columns: repeat(5, 1fr);">
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="美食"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="汽车票"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="宠物"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="汽车票"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="宠物"></category-item>
|
||||||
|
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="美食"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="汽车票"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="宠物"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="汽车票"></category-item>
|
||||||
|
<category-item src="https://www.httpbin.org/image/png" title="宠物"></category-item>
|
||||||
|
</view>
|
||||||
|
</swiper-item>
|
||||||
|
|
||||||
<swiper-item v-for="item in pic.list" :key="item.id">
|
<swiper-item v-for="item in pic.list" :key="item.id">
|
||||||
<image @tap="previewImage(item)" :src="item.url"></image>
|
<image @tap="previewImage(item)" :src="item.url"></image>
|
||||||
</swiper-item>
|
</swiper-item>
|
||||||
@ -31,8 +46,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
import {useUserStore} from "../../stores/modules/user";
|
||||||
|
import CategoryItem from "./components/category-item/index.vue";
|
||||||
let timer = null
|
let timer = null
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
CategoryItem
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
navHeight: 0,
|
navHeight: 0,
|
||||||
@ -71,6 +91,8 @@ export default {
|
|||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
this.now = new moment().format('YYYY-MM-DD HH:mm:ss')
|
this.now = new moment().format('YYYY-MM-DD HH:mm:ss')
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
|
useUserStore().userInfo.name = "法外狂徒"
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
previewImage(item) {
|
previewImage(item) {
|
||||||
|
@ -30,14 +30,22 @@
|
|||||||
</uni-card>
|
</uni-card>
|
||||||
|
|
||||||
<button @tap="back">返回上一页</button>
|
<button @tap="back">返回上一页</button>
|
||||||
|
<button type="warn" @tap="cleanStorage">清空本地存储</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import {useUserStore} from "../../stores/modules/user";
|
||||||
|
|
||||||
function back() {
|
function back() {
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
animationDuration: 100
|
animationDuration: 100
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanStorage(){
|
||||||
|
useUserStore().clearUserInfo()
|
||||||
|
uni.clearStorage()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
6
src/stores/index.js
Normal file
6
src/stores/index.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import {createPinia} from 'pinia'
|
||||||
|
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||||
|
const pinia = createPinia()
|
||||||
|
pinia.use(piniaPluginPersistedstate)
|
||||||
|
|
||||||
|
export default pinia
|
30
src/stores/modules/user.js
Normal file
30
src/stores/modules/user.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import {defineStore} from 'pinia'
|
||||||
|
import {reactive} from 'vue'
|
||||||
|
|
||||||
|
export const useUserStore = defineStore('user', () =>{
|
||||||
|
const userInfo = reactive({
|
||||||
|
id: "",
|
||||||
|
name: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
function clearUserInfo() {
|
||||||
|
userInfo.id = ""
|
||||||
|
userInfo.name = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
userInfo,
|
||||||
|
clearUserInfo
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
persist: {
|
||||||
|
storage: {
|
||||||
|
getItem(key){
|
||||||
|
return uni.getStorageSync(key)
|
||||||
|
},
|
||||||
|
setItem(key, value){
|
||||||
|
uni.setStorageSync(key, value)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user