1
0
Fork 0

Compare commits

..

2 Commits

Author SHA1 Message Date
suguo 0937dc0eac UP 2025-05-02 15:25:49 +08:00
lemons e8e80f14b1 Merge pull request 'UP' (#1) from xinyu.yao/hello-lemons:master into master
Reviewed-on: lemons/hello-lemons#1
2025-04-25 13:39:47 +00:00
4 changed files with 40 additions and 17 deletions

23
src/store/product.js Normal file
View File

@ -0,0 +1,23 @@
import {defineStore} from 'pinia'
export const useProductStore = defineStore('product', {
state: () => ({
products: [],
total: 0,
}),
actions: {
productSet(data,total) {
this.products = data;
// this.products.push(...data); //追加数据
this.total=total; //这里会更新
},
productTotalSet(total){
this.total=total
}
},
getters: {
count: (state) => state.products.length,
total: (state) => state.total,
}
})

View File

@ -2,7 +2,7 @@
<template>
<el-form :model="form" label-width="auto" style="max-width: 600px">
<el-form-item label="Activity name">
<el-input v-model="form.name" />
<el-input v-model=" productStore.count" />
</el-form-item>
<el-form-item label="Activity zone">
<el-select v-model="form.region" placeholder="please select your zone">
@ -66,14 +66,14 @@
</template>
<div>
<p>hello about</p>
<p>Count: {{ tokenStore.count }}</p>
<p>Count: {{ productStore.count }}</p>
</div>
</template>
<script setup>
import { useTokenStore } from '../store/token.js';
import { useProductStore } from '../store/product.js';
const tokenStore=useTokenStore();
const productStore=useProductStore();
</script>
<style scoped>

View File

@ -1,9 +1,7 @@
<template>
<div>
<p>hello home</p>
<p>Count: {{ tokenStore.count }}</p>
<button @click="tokenStore.increment">Increment</button>
<button @click="tokenStore.incrementAsync">Increment Async</button>
<p>Count: {{ productStore.count}}</p>
<router-link to="/about">About</router-link>
<el-alert
v-if="showAlert"
@ -19,26 +17,27 @@
</template>
<script setup>
import { ref } from 'vue';
import { ref, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import request from '../api/request.js'
import { useTokenStore } from '../store/token.js';
const tokenStore=useTokenStore()
import { useProductStore } from '../store/product.js';
// el-alert
const showAlert = ref(false);
const alertTitle = ref('');
const alertType = ref('warning');
const alertDescription = ref('');
const productStore=useProductStore();
const fetchData = async()=>{
try {
const response=await request.get('/api/product')
console.log(response)
const response=await request.get('/api/product');
productStore.productSet(response.data,100);
} catch (error) {
alertTitle.value = 'Error';
alertDescription.value = error.message;
showAlert.value = true;
console.log(error);
}
}
onMounted(()=>{
fetchData()
})
</script>

1
test.http Normal file
View File

@ -0,0 +1 @@
GET http://w3.myschools.me/api/product HTTP/1.1