国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 熱點(diǎn) > 微信 > 正文

vue實(shí)現(xiàn)的微信機(jī)器人聊天功能案例【附源碼下載】

2024-07-22 01:19:03
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了vue實(shí)現(xiàn)的微信機(jī)器人聊天功能。分享給大家供大家參考,具體如下:

先看效果:

實(shí)現(xiàn)過(guò)程:

<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <title>HTML5模擬微信聊天界面</title>  <style>    /**重置標(biāo)簽?zāi)J(rèn)樣式*/    * {      margin: 0;      padding: 0;      list-style: none;      font-family: '微軟雅黑'    }    #container {      width: 450px;      height: 780px;      background: #eee;      margin: 80px auto 0;      position: relative;      box-shadow: 20px 20px 55px #777;    }    .header {      background: #000;      height: 40px;      color: #fff;      line-height: 34px;      font-size: 20px;      padding: 0 10px;    }    .footer {      width: 430px;      height: 50px;      background: #666;      position: absolute;      bottom: 0;      padding: 10px;    }    .footer input {      width: 360px;      height: 45px;      outline: none;      font-size: 20px;      text-indent: 10px;      position: absolute;      border-radius: 6px;      right: 80px;    }    .footer span {      display: inline-block;      width: 62px;      height: 48px;      background: #ccc;      font-weight: 900;      line-height: 45px;      cursor: pointer;      text-align: center;      position: absolute;      right: 10px;      border-radius: 6px;    }    .footer span:hover {      color: #fff;      background: #999;    }    /* #user_face_icon {      display: inline-block;      background: red;      width: 60px;      height: 60px;      border-radius: 30px;      position: absolute;      bottom: 6px;      left: 14px;      cursor: pointer;      overflow: hidden;    } */    img {      width: 60px;      height: 60px;    }    .content {      font-size: 20px;      width: 435px;      height: 662px;      overflow: auto;      padding: 5px;    }    .content li {      margin-top: 10px;      padding-left: 10px;      width: 412px;      display: block;      clear: both;      overflow: hidden;    }    .content li img {      float: left;    }    .content li span {      background: #7cfc00;      padding: 10px;      border-radius: 10px;      float: left;      margin: 6px 10px 0 10px;      max-width: 310px;      border: 1px solid #ccc;      box-shadow: 0 0 3px #ccc;    }    .content li img.imgleft {      float: left;    }    .content li img.imgright {      float: right;    }    .content li span.spanleft {      float: left;      background: #fff;    }    .content li span.spanright {      float: right;      background: #7cfc00;    }  </style></head><body>  <div id="container">    <div class="header">      <span style="float: left;">微信聊天界面</span>      <span style="float: right;">14:21</span>    </div>    <ul class="content">      <li v-for="(item, index) in messageList" >        <img :src="'./img/'+(item.isSelf?'r.png':'l.png')" :class="'img'+(item.isSelf?'right':'left')">        <span :class="'span'+(item.isSelf?'right':'left')">{{item.message}}</span>      </li>    </ul>    <div class="footer">      <!-- 添加輸入內(nèi)容 -->      <input id="text" type="text" placeholder="說(shuō)點(diǎn)什么吧..." v-model="inputValue" @keyup.enter="chat">      <!-- 給發(fā)送也綁定一個(gè)事件 -->      <span id="btn" @click="chat">發(fā)送</span>    </div>  </div>  <!-- 導(dǎo)入vue -->  <script src="./lib/vue.js"></script>  <!-- 導(dǎo)入jQuery -->  <script src="./lib/jquery-1.12.4.min.js"></script>  <!-- 開(kāi)始代碼 -->  <script>    /*    思路分析:    一.定義聊天信息數(shù)組格式    [      {       message:'',       isSelf:true(自己)/false(機(jī)器人)      }    ]    二.獲取自己輸入內(nèi)容,將內(nèi)容渲染到頁(yè)面    三.獲取機(jī)器人接口內(nèi)容,也將內(nèi)容渲染到頁(yè)面     */    //一:    let app = new Vue({      el: "#container",      data: {        //輸入內(nèi)容,雙向數(shù)據(jù)綁定        inputValue: '',        //聊天窗口內(nèi)容        messageList: []      },      methods: {        chat() {          // console.log(this.inputValue);          // console.log(this);          // 二.獲取自己輸入內(nèi)容,將內(nèi)容渲染到頁(yè)面          this.messageList.push({            message: this.inputValue,            isSelf: true          })          // 三.獲取機(jī)器人接口內(nèi)容,也將內(nèi)容渲染到頁(yè)面          $.ajax({            url:'http://www.tuling123.com/openapi/api',            data:{              userid:1,//添加id,實(shí)現(xiàn)上下文連貫              key:'b6ef78a0c1f24fee90d2317139b9c3d5',              info:this.inputValue            },            // 注意使用箭頭函數(shù),不然里面的this會(huì)發(fā)生變化            success:(obj)=>{              console.log(obj);              // 三.獲取機(jī)器人接口內(nèi)容,也將內(nèi)容渲染到頁(yè)面              this.messageList.push({                message:obj.text,                isSelf:false              })            }          })         this.inputValue='';  //最后清除文本框        }      },    })  </script></body></html>            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尖扎县| 南昌市| 马尔康县| 宜章县| 合水县| 呼和浩特市| 和田市| 甘谷县| 慈利县| 蒙城县| 青河县| 隆林| 乡宁县| 博乐市| 昭平县| 沛县| 宾阳县| 金湖县| 汝阳县| 临潭县| 孟连| 九龙城区| 河津市| 布尔津县| 深泽县| 灵寿县| 蓝山县| 佳木斯市| 禹城市| 信丰县| 丰台区| 虹口区| 灵石县| 朝阳区| 林口县| 宁明县| 蒲城县| 迁西县| 金阳县| 遂溪县| 安福县|