欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2019年02月18日 14:56:21   作者:庚中  
這篇文章主要介紹了vue實現(xiàn)的微信機器人聊天功能,結(jié)合實例形式分析了基于vue.js的微信機器人聊天相關(guān)界面布局、ajax交互等操作技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下

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

先看效果:

實現(xiàn)過程:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>HTML5模擬微信聊天界面</title>
  <style>
    /**重置標簽默認樣式*/
    * {
      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="說點什么吧..." v-model="inputValue" @keyup.enter="chat">
      <!-- 給發(fā)送也綁定一個事件 -->
      <span id="btn" @click="chat">發(fā)送</span>
    </div>
  </div>
  <!-- 導入vue -->
  <script src="./lib/vue.js"></script>
  <!-- 導入jQuery -->
  <script src="./lib/jquery-1.12.4.min.js"></script>
  <!-- 開始代碼 -->
  <script>
    /*
    思路分析:
    一.定義聊天信息數(shù)組格式
    [
      {
       message:'',
       isSelf:true(自己)/false(機器人)
      }
    ]
    二.獲取自己輸入內(nèi)容,將內(nèi)容渲染到頁面
    三.獲取機器人接口內(nèi)容,也將內(nèi)容渲染到頁面
     */
    //一:
    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)容渲染到頁面
          this.messageList.push({
            message: this.inputValue,
            isSelf: true
          })
          // 三.獲取機器人接口內(nèi)容,也將內(nèi)容渲染到頁面
          $.ajax({
            url:'http://www.tuling123.com/openapi/api',
            data:{
              userid:1,//添加id,實現(xiàn)上下文連貫
              key:'b6ef78a0c1f24fee90d2317139b9c3d5',
              info:this.inputValue
            },
            // 注意使用箭頭函數(shù),不然里面的this會發(fā)生變化
            success:(obj)=>{
              console.log(obj);
              // 三.獲取機器人接口內(nèi)容,也將內(nèi)容渲染到頁面
              this.messageList.push({
                message:obj.text,
                isSelf:false
              })
            }
          })
         this.inputValue='';  //最后清除文本框
        }
      },
    })
  </script>
</body>
</html>

附:gethub源碼地址:https://github.com/huanggengzhong/jiqiren

還可以點擊此處本站下載

希望本文所述對大家vue.js程序設(shè)計有所幫助。

相關(guān)文章

  • Vue之beforeEach非登錄不能訪問的實現(xiàn)(代碼親測)

    Vue之beforeEach非登錄不能訪問的實現(xiàn)(代碼親測)

    這篇文章主要介紹了Vue之beforeEach非登錄不能訪問的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-07-07
  • 使用vue實現(xiàn)玉兔迎春圖高亮示例詳解

    使用vue實現(xiàn)玉兔迎春圖高亮示例詳解

    這篇文章主要為大家介紹了使用vue實現(xiàn)玉兔迎春圖高亮示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • vue實現(xiàn)調(diào)取手機攝像頭和相冊功能

    vue實現(xiàn)調(diào)取手機攝像頭和相冊功能

    這篇文章主要為大家詳細介紹了vue實現(xiàn)調(diào)取手機攝像頭和相冊功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • vue2.0使用md-edit編輯器的過程

    vue2.0使用md-edit編輯器的過程

    這篇文章主要介紹了vue2.0+使用md-edit編輯器的解決方案,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-02-02
  • cesium開發(fā)之如何在vue項目中使用cesium,使用離線地圖資源

    cesium開發(fā)之如何在vue項目中使用cesium,使用離線地圖資源

    這篇文章主要介紹了cesium開發(fā)之如何在vue項目中使用cesium,使用離線地圖資源問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue3.0透傳屬性和事件的使用方式舉例

    vue3.0透傳屬性和事件的使用方式舉例

    這篇文章主要給大家介紹了關(guān)于vue3.0透傳屬性和事件使用的相關(guān)資料,透傳attribute指的是傳遞給一個組件,卻沒有被該組件聲明為props或emits的attribute或者v-on事件監(jiān)聽器,需要的朋友可以參考下
    2024-01-01
  • 基于vue 動態(tài)加載圖片src的解決方法

    基于vue 動態(tài)加載圖片src的解決方法

    下面小編就為大家分享一篇基于vue 動態(tài)加載圖片src的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • vue中數(shù)據(jù)字典dicts的簡單說明和用法介紹

    vue中數(shù)據(jù)字典dicts的簡單說明和用法介紹

    這篇文章主要給大家介紹了關(guān)于vue中數(shù)據(jù)字典dicts的簡單說明和用法的相關(guān)資料,如果您想在Vue中使用字典查詢,您可以使用Vue的計算屬性和方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-01-01
  • Vuex的各個模塊封裝的實現(xiàn)

    Vuex的各個模塊封裝的實現(xiàn)

    這篇文章主要介紹了Vuex的各個模塊封裝的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-06-06
  • vue中props值的傳遞詳解

    vue中props值的傳遞詳解

    這篇文章主要介紹了vue中props值的傳遞,在vue中父組件要正向的向子組件傳遞數(shù)據(jù)或者參數(shù),子組件接收到后根據(jù)參數(shù)的不同來進行對應的渲染,這個正向的數(shù)據(jù)傳遞在vue組件中就是通過props來實現(xiàn)的,需要的朋友可以參考下
    2009-05-05

最新評論