Compare commits
No commits in common. "master" and "master" have entirely different histories.
|
|
@ -1,23 +0,0 @@
|
||||||
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,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<template>
|
<template>
|
||||||
<el-form :model="form" label-width="auto" style="max-width: 600px">
|
<el-form :model="form" label-width="auto" style="max-width: 600px">
|
||||||
<el-form-item label="Activity name">
|
<el-form-item label="Activity name">
|
||||||
<el-input v-model=" productStore.count" />
|
<el-input v-model="form.name" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Activity zone">
|
<el-form-item label="Activity zone">
|
||||||
<el-select v-model="form.region" placeholder="please select your zone">
|
<el-select v-model="form.region" placeholder="please select your zone">
|
||||||
|
|
@ -66,14 +66,14 @@
|
||||||
</template>
|
</template>
|
||||||
<div>
|
<div>
|
||||||
<p>hello about</p>
|
<p>hello about</p>
|
||||||
<p>Count: {{ productStore.count }}</p>
|
<p>Count: {{ tokenStore.count }}</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useProductStore } from '../store/product.js';
|
import { useTokenStore } from '../store/token.js';
|
||||||
|
|
||||||
const productStore=useProductStore();
|
const tokenStore=useTokenStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<p>hello home</p>
|
<p>hello home</p>
|
||||||
<p>Count: {{ productStore.count}}</p>
|
<p>Count: {{ tokenStore.count }}</p>
|
||||||
|
<button @click="tokenStore.increment">Increment</button>
|
||||||
|
<button @click="tokenStore.incrementAsync">Increment Async</button>
|
||||||
<router-link to="/about">About</router-link>
|
<router-link to="/about">About</router-link>
|
||||||
<el-alert
|
<el-alert
|
||||||
v-if="showAlert"
|
v-if="showAlert"
|
||||||
|
|
@ -17,27 +19,26 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
|
||||||
import request from '../api/request.js'
|
import request from '../api/request.js'
|
||||||
import { useProductStore } from '../store/product.js';
|
import { useTokenStore } from '../store/token.js';
|
||||||
|
|
||||||
|
const tokenStore=useTokenStore()
|
||||||
|
|
||||||
// 定义用于控制 el-alert 显示的变量
|
// 定义用于控制 el-alert 显示的变量
|
||||||
const showAlert = ref(false);
|
const showAlert = ref(false);
|
||||||
const alertTitle = ref('');
|
const alertTitle = ref('');
|
||||||
const alertType = ref('warning');
|
const alertType = ref('warning');
|
||||||
const alertDescription = ref('');
|
const alertDescription = ref('');
|
||||||
const productStore=useProductStore();
|
|
||||||
const fetchData = async()=>{
|
const fetchData = async()=>{
|
||||||
try {
|
try {
|
||||||
const response=await request.get('/api/product');
|
const response=await request.get('/api/product')
|
||||||
productStore.productSet(response.data,100);
|
console.log(response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
alertTitle.value = 'Error';
|
||||||
|
alertDescription.value = error.message;
|
||||||
|
showAlert.value = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(()=>{
|
|
||||||
fetchData()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue