修改删除动态和评论Bug

main
QMZ 1 month ago
parent 4deb0096c9
commit a3dba65371

@ -60,7 +60,7 @@
<script> <script>
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import axios from 'axios'; import axios from '@/utils/axiosConfig';
import {getUserId} from '@/token/auth'; import {getUserId} from '@/token/auth';
@ -73,7 +73,7 @@
}, },
data() { data() {
return { return {
userid:0, userid:1,
showForm: false, // showForm: false, //
radio: '日常动态', radio: '日常动态',
form: { form: {
@ -127,6 +127,7 @@
this.$message.error('内容不能为空'); this.$message.error('内容不能为空');
return; return;
} }
const newPost = { const newPost = {
userid:getUserId(), userid:getUserId(),
username: '用户', username: '用户',
@ -137,21 +138,23 @@
likecount: 0, likecount: 0,
commentcount: 0, commentcount: 0,
isfamilystory: this.radio === '家族故事' ? true : false, isfamilystory: this.radio === '家族故事' ? true : false,
postid:999,
}; };
try { try {
const response = await axios.post('http://localhost:8082/loveforest/posts/addpost', newPost, { const response = await axios.post('/posts/addpost', newPost, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json' 'Accept': 'application/json'
} }
}); });
if(response.data==="增加动态成功!") if(response.startsWith("增加动态成功!"))
{ {
const postid = response.replace("增加动态成功!", '').trim();
this.$message.success("增加动态成功!"); this.$message.success("增加动态成功!");
newPost.postid=postid;
this.$emit('post-submitted', newPost); this.$emit('post-submitted', newPost);
this.form.content = ''; this.form.content = '';
@ -160,7 +163,7 @@
} }
else{ else{
this.$message.error(response.data); console.error(response);
} }
} catch (error) { } catch (error) {

@ -194,6 +194,7 @@
async loadData() { async loadData() {
try { try {
this.userid= getUserId(); this.userid= getUserId();
// //
await this.fllowlist(); await this.fllowlist();
await this.loadhotpost(); await this.loadhotpost();
@ -358,7 +359,7 @@
try { try {
const response = await axios.get(`/comments/postid=${postid}`); const response = await axios.get(`/comments/postid=${postid}`);
this.checkPosts[index].comments = response; this.checkPosts[index].comments = response;
//user
this.checkPosts[index].isCommentsVisible = !this.checkPosts[index].isCommentsVisible; this.checkPosts[index].isCommentsVisible = !this.checkPosts[index].isCommentsVisible;
} catch (error) { } catch (error) {
@ -381,13 +382,15 @@
'Accept': 'application/json' 'Accept': 'application/json'
} }
}); });
if (response=== "评论成功!") { if (response.startsWith ("评论成功!")) {
this.$message.success("评论成功!"); this.$message.success("评论成功!");
const id = response.replace("评论成功!", '').trim();
this.checkPosts[index].comments.push({ this.checkPosts[index].comments.push({
username: '用户名',//user username: '用户名',//user
postid: postid, postid: postid,
content: commentText content: commentText,
commentid:id,
userid:this.userid
}); });
this.checkPosts[index].commentCount += 1; this.checkPosts[index].commentCount += 1;
} }

Loading…
Cancel
Save