【页面案例汇总】微信小程序论坛讨论页面

<template>
  <view class="container">
    <view class="header">{{ post.title }}</view>
    <view class="content">{{ post.content }}</view>
    <view class="comments">
      <view v-for="comment in comments" :key="comment.id" class="comment">
        <view class="username">{{ comment.username }}</view>
        <view class="text">{{ comment.text }}</view>
      </view>
    </view>
    <view class="add-comment">
      <input v-model="newComment" placeholder="发表评论" />
      <button @click="addComment">发表</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      post: {
        title: "这是一个讨论帖子",
        content: "这是帖子的内容,大家可以在评论区讨论。",
      },
      comments: [
        { id: 1, username: "Alice", text: "非常好的帖子!" },
        { id: 2, username: "Bob", text: "同意楼上的观点!" },
      ],
      newComment: "",
    };
  },
  methods: {
    addComment() {
      const newId = this.comments.length + 1;
      this.comments.push({
        id: newId,
        username: "匿名用户",
        text: this.newComment,
      });
      this.newComment = "";
    },
  },
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
}

.header {
  font-size: 24px;
  font-weight: bold;
}

.content {
  margin-top: 20px;
  line-height: 1.5;
}

.comments {
  margin-top: 20px;
  width: 100%;
}

.comment {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.username {
  font-weight: bold;
}

.add-comment {
  margin-top: 20px;
  display: flex;
}

input {
  flex-grow: 1;
  margin-right: 10px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

button {
  padding: 10px;
  background-color: #007aff;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
</style>

在这个示例中,我们使用了uniapp的模板语法来动态渲染帖子的标题、内容和评论列表,并使用v-for指令遍历评论列表中的每个评论,并使用v-model指令绑定用户输入的新评论内容。同时,我们还定义了一个addComment方法,在用户点击“发表”按钮时添加新评论到评论列表中。最后,我们使用了uniapp的样式语法来美化页面的布局和样式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值