Browse Source

跨域,请求判断修改

master
maziyang 8 hours ago
parent
commit
c6502cc358
  1. 9
      src/components/home/AsideMenu.vue
  2. 3
      src/utils/request.js
  3. 46
      src/views/Article/Article.vue
  4. 1
      src/views/VoteRecord/VoteRecord.vue
  5. 9
      vite.config.js

9
src/components/home/AsideMenu.vue

@ -34,4 +34,11 @@
<script setup>
</script>
<style scoped></style>
<style scoped>
.logo-text{
color: azure;
font-size: large;
display: flex;
justify-content: center;
}
</style>

3
src/utils/request.js

@ -2,7 +2,8 @@ import axios from 'axios';
export const request = axios.create({
baseURL: 'http://192.168.8.237:8000',
// baseURL: 'http://192.168.8.237:8000',
baseURL: '/api',
timeout:10000,
headers: {
'Content-Type': 'application/json'

46
src/views/Article/Article.vue

@ -1,5 +1,5 @@
<template>
<el-form :model="form" label-width="auto" :rules="rules" ref="elFormRef" style="max-width: 600px">
<el-form :model="form" label-width="auto" :rules="rules" ref="elFormRef" style="max-width: 600px">
<el-form-item label="文章标题" prop="articleTitle">
<el-input v-model="form.articleTitle" />
</el-form-item>
@ -49,7 +49,7 @@
</template>
<script setup>
import { reactive, ref } from 'vue'
import {ElMessage, ElMessageBox, ElForm } from 'element-plus'
import { ElMessage, ElMessageBox, ElForm } from 'element-plus'
import { Delete, Plus } from '@element-plus/icons-vue'
import { useArticleStore } from '@/stores/article'
import { useUserStore } from '@/stores/user'
@ -57,12 +57,12 @@ let elFormRef = ref()
let optionIndex = ref(3)
let buttonLoading = ref(false)
//
const clearVoteInfomation = () =>{
optionIndex.value = 3
form.voteTitle = '';
form.deadlineTime = '';
form.multiOption = false
form.optionList = []
const clearVoteInfomation = () => {
optionIndex.value = 3
form.voteTitle = '';
form.deadlineTime = '';
form.multiOption = false
form.optionList = []
}
const handleVoteToggle = (value) => {
clearVoteInfomation()
@ -71,7 +71,7 @@ const handleVoteToggle = (value) => {
{ optionIndex: 1, optionContent: '' },
{ optionIndex: 2, optionContent: '' }
];
}
}
};
//
const addOption = () => {
@ -96,7 +96,7 @@ let form = reactive({
voteStatus: false,
voteTitle: '',
optionList: [],
multiOption:false,
multiOption: false,
deadlineTime: ''
})
const rules = reactive({
@ -144,21 +144,25 @@ const onSubmit = async () => {
console.log('表单验证失败', error)
}
if (valid) {
buttonLoading.value = true
buttonLoading.value = true
console.log('表单验证通过')
try {
form.userId = useUserStore().userId
await useArticleStore().addArticle(form)
ElMessage.success('发表成功!')
form.articleTitle = ''
form.articleContent = ''
form.voteStatus = false
clearVoteInfomation()
let res = await useArticleStore().addArticle(form)
if (res.status == 200) {
ElMessage.success('发表成功!')
form.articleTitle = ''
form.articleContent = ''
form.voteStatus = false
clearVoteInfomation()
} else {
ElMessage.error('发布失败,请重试!')
}
} catch (error) {
ElMessage.error('发布失败,请重试!')
console.log( error)
} finally{
buttonLoading.value = false
ElMessage.error('发布失败,请重试!')
console.log(error)
} finally {
buttonLoading.value = false
}
}

1
src/views/VoteRecord/VoteRecord.vue

@ -95,7 +95,6 @@ const fetchVoteData = async () => {
deadlineTime: condition.deadlineTime,
status: condition.status
})
console.log(params)
const res = await useVoteRecordStore().getAllVotes(params)
console.log(res)
tableData.value = res.data.data.rows

9
vite.config.js

@ -15,4 +15,13 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server:{
proxy:{
'/api':{
target:'http://192.168.8.237:8000',
changeOrigin:true,
rewrite:(path)=>path.replace(/^\/api/,'')
}
}
}
})
Loading…
Cancel
Save