【页面案例汇总】微信小程序在线客服页面

该篇文章介绍了如何使用Vue.js构建一个简单的在线客服页面,用户可以输入问题并发送,客服消息通过定时器模拟延迟回复。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在线客服页面:

<template>
  <view class="container">
    <view class="chatroom">
      <view class="message" v-for="(message, index) in messages" :key="index">
        <view v-if="message.type == 'customer'" class="customer-message">{{ message.content }}</view>
        <view v-else class="agent-message">{{ message.content }}</view>
      </view>
    </view>
    <view class="input-container">
      <input class="input-message" placeholder="请输入您的问题" @confirm="sendMessage" v-model="messageInput"></input>
      <view class="send-button" @click="sendMessage">发送</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      messages: [],
      messageInput: ""
    };
  },
  methods: {
    sendMessage() {
      if (this.messageInput == "") {
        return;
      }
      this.messages.push({
        type: "customer",
        content: this.messageInput
      });
      this.messageInput = "";
      // 模拟客服回复
      setTimeout(() => {
        this.messages.push({
          type: "agent",
          content: "您好,有什么可以帮助您的呢?"
        });
      }, 1000);
    }
  }
};
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px;
}

.chatroom {
  flex-grow: 1;
  overflow-y: auto;
}

.message {
  margin-bottom: 10px;
}

.customer-message {
  background-color: #eee;
  padding: 6px 10px;
  border-radius: 10px;
  max-width: 60%;
  align-self: flex-start;
}

.agent-message {
  background-color: #007aff;
  color: #fff;
  padding: 6px 10px;
  border-radius: 10px;
  max-width: 60%;
  align-self: flex-end;
}

.input-container {
  display: flex;
  margin-top: 20px;
}

.input-message {
  flex-grow: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #eee;
}

.send-button {
  background-color: #007aff;
  color: #fff;
  padding: 10px;
  border-radius: 10px;
  margin-left: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
</style>

这是一个简单的在线客服页面,由一个聊天窗口和一个输入框组成。用户输入问题后,点击发送按钮或者按下回车键,问题将会发送给客服。客服在一定时间(这里是1秒)后会模拟回复一条消息,这条消息会显示在聊天窗口中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值