getDiscussList(page) { this.$http.get('discussjinrishici/list', {params: {page, limit: this.pageSize, refid: this.detail.id}}).then(res => { if (res.data.code == 0) { this.infoList = res.data.data.list; this.total = res.data.data.total; this.pageSize = res.data.data.pageSize;this.pageSizes = [this.pageSize, this.pageSize*2, this.pageSize*3, this.pageSize*5]; this.totalPage = res.data.data.totalPage; } }); }, submitForm(formName) { let sensitiveWords = ""; let sensitiveWordsArr = []; if(sensitiveWords) { sensitiveWordsArr = sensitiveWords.split(","); } for(var i=0; i<sensitiveWordsArr.length; i++){ //全局替换 var reg = new RegExp(sensitiveWordsArr[i],"g"); //判断内容中是否包括敏感词 if (this.form.content.indexOf(sensitiveWordsArr[i]) > -1) { // 将敏感词替换为 ** this.form.content = this.form.content.replace(reg,"**"); } } this.$refs[formName].validate((valid) => { if (valid) { this.form.refid = this.detail.id; this.form.avatarurl = localStorage.getItem('headportrait')?localStorage.getItem('headportrait'):''; this.$http.post('discussjinrishici/add', this.form).then(res => { if (res.data.code == 0) { this.form.content = ''; this.getDiscussList(1); this.$message({ type: 'success', message: '评论成功!', duration: 1500, }); } }); } else { return false; } }); }, resetForm(formName) { this.$refs[formName].resetFields(); }, }, components: { CountDown } } </script>
时间: 2023-12-30 22:04:58 浏览: 103
Java_JSP_Paging.zip_jsp分页_site:www.pudn.com
这是一个Vue.js组件,包含了获取评论列表、提交评论表单、重置表单等功能。在获取评论列表时,通过发送GET请求获取指定页数的评论列表,并将数据赋值给组件的infoList、total、pageSize、totalPage等变量。在提交评论表单时,先检测评论内容中是否包含敏感词汇,如果有则将敏感词替换为**,然后通过POST请求将评论数据提交至服务器,并在返回结果为成功时,清空评论内容并重新获取评论列表。组件还包含了一个名为CountDown的子组件。
阅读全文