日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Vue實現聊天界面

瀏覽:237日期:2022-09-28 15:19:59

本文實例為大家分享了Vue實現聊天界面展示的具體代碼,供大家參考,具體內容如下

1.功能需求

根據索引選擇跟不同的人進行聊天

Vue實現聊天界面

Vue實現聊天界面

2.代碼展示

mock.js:

import Mock from ’mockjs’Mock.mock('/chatchild',{ ’result’:[{ id:'001', imgurl:'/static/image/10.jpg', name:'XKDK', date:'09:23', words:'哈哈,好噠'},// ... ... ]});export default Mock

userinfo.js:

let usermsg={ id:'122', imgurl:'/static/image/8.jpg', words:'是的!', data:{id:'1529',imgurl:'/static/image/7.jpg',name:'易安居士',words:[ {info:'在嗎?'}, {info:'不在'}, {info:'你把草稿交了沒有'}, {info:'我今天中午吃完飯 就一直看劇了'}, {info:'我發現我真的是宅女'}, {info:'哈哈哈'}, {info:'有空找你約頓飯'}, {info:'嗯嗯'}, {info:'反正影響不大'}] }}export default usermsg

index.js:

import Vue from ’vue’import Router from ’vue-router’import Chat from ’../components/Chat.vue’import ChatDetail from ’../components/Pages/ChatDetail.vue’Vue.use(Router)export default new Router({ routes: [ { path: ’/Chat ’, component: Chat }, { path:’/ChatDetail’, component:ChatDetail } ]})// 解決路由報錯的代碼const originalPush = Router.prototype.pushRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err)}

Chat.vue:

<template> <div id='chat'> <Bottom /> <Header :name='msg' /> <div class='chat_alluser'> <div ref='chatuser' @click='checkChild(index)' v-for='(item,index) in chat' :key='index'><ChatChild :imgsrc='item.imgurl' :nickname='item.name' :time='item.date' :word='item.words' /> </div> </div> </div></template><script>import Bottom from '../components/Menu/Bottom';import Header from '../components/Menu/Header';import ChatChild from '../components/Pages/ChatChild';export default { name: 'Chat', components: { Bottom: Bottom, Header: Header, ChatChild: ChatChild }, data() { return { msg: '微信', chat: null, name: null }; }, mounted() { this.$axios.get('/chatchild').then(res => { this.chat = res.data.result; }); }, methods: { checkChild(index) { this.$refs.chatuser[index].style.backgroundColor = 'rgb(240,240,240)'; // 動態dom元素渲染完成之后,跳轉到另一個界面(ChatDetail) // 獲取動態name let username = this.chat[index].name; this.$nextTick(() => {this.$router.push({ path: '/ChatDetail', query: { name: username }}); }); } }};</script><style lang='scss' scope>#chat { width: 100%; .chat_alluser { margin-bottom: 7.5rem; .chatuser { position: relative; top: 3.5rem; padding: 0.3rem 0; } }}</style>

父組件使用子組件里的屬性和方法:在父組件中的子組件上定義ref屬性,通過 this.$ refs.name.屬性或this.$refs.name.方法

ChatChild.vue:

<template> <div id='chatchild'> <div class='photo'> <img :src='http://www.b3g6.com/bcjs/imgsrc' alt /> </div> <div class='content'> <div> <span class='content_nickname'>{{nickname}}</span> <span class='content_time'>{{time}}</span> </div> <span class='content_word'>{{word}}</span> </div> </div></template><script>export default { name: 'ChatChild', props:{ ’imgsrc’:String, ’nickname’:String, ’time’:String, ’word’:String }};</script><style lang='scss' scope>#chatchild { width: 100%; height: 5rem; display: flex; flex-direction: row; box-sizing: border-box; .photo { flex: 1; height: 5rem; img{object-fit: cover;width: 4rem;height: 4rem;border-radius: 5px;display: block;margin: 0 auto;margin-top: 0.5rem;margin-left: 1rem; } } .content { flex: 4; height: 5rem; border-bottom: 0.5px solid rgb(240, 240, 240); padding-left: 0.5rem; padding-top: 0.5rem; box-sizing: border-box; div{ .content_nickname{display: inline-block;font-size: 1.1rem;margin-top: 0.3rem; } .content_time{float: right;margin-right: 1rem;color: rgb(209, 206, 206);font-size: 0.8rem; } } .content_word{ color: rgb(209, 206, 206); font-size: 0.8rem; display: block; margin-top: 0.5rem; } }}</style>

ChatDetail.vue:

<template> <div id='chatdetail'> <div class='chattop'> <div @click='goback' class='chattop_back'><icon-svg icon- /> </div> <div class='chattop_name'>{{name}}</div> <div class='chattop_more'><icon-svg icon- /> </div> </div> <div class='chatcontent'> <ChatMsg ref='chatmsg' /> </div> <div class='chatfooter'> <div @click='changeSound'><icon-svg :icon- /> </div> <div><input ref='sendcontent' @keypress='sendmsg' :type='istype' :value='isvalue' /> </div> <div><icon-svg icon- /> </div> <div><icon-svg icon- /> </div> </div> </div></template><script>import ChatMsg from './ChatMsg';export default { name: 'ChatDetail', data() { return { name: null, issound: 'xiaoxitongzhi', istype: 'text', isvalue: '', isshow: false, tomsg: '', msgchild: null }; }, components: { ChatMsg: ChatMsg }, mounted() { this.name = this.$route.query.name; this.msgchild = this.$refs.chatmsg; }, methods: { // 進行返回操作 goback() { this.$router.go(-1); }, // 切換input的類型 changeSound() { // 在data中定義一個變量isshow:false,利用this.isshow與!this.isshow進行切換 if (!this.isshow) {this.isshow = true;this.issound = 'yuyin';this.istype = 'button';this.isvalue = '按住 說話'; } else {this.isshow = false;this.issound = 'xiaoxitongzhi';this.istype = 'text';this.isvalue = ''; } }, // 發送消息 sendmsg(e) { // 1、用ref定義輸入回復內容的input文本框,定義sendcontent變量接收其value值(輸入的內容) let sendcontent = this.$refs.sendcontent.value; if (e.keyCode === 13 && sendcontent.split(' ').join('').length !== 0) {// 2、將ChatDetail(父)組件中的sendcontent(文本框輸入的值)先用tomsg接收this.tomsg = sendcontent;// 3、用ref定義ChatMsg(子)組件,并在mounted中使用$refs獲取,即this.msgchild// 4、調子組件里的方法,并將tomsg傳到ChatMsg(子)組件(具體的聊天內容)中this.msgchild.saveMsg(this.tomsg);// 5、發送完一條信息之后,需清空文本框this.$refs.sendcontent.value = '';// 回車時,調用子組件的隨機消息的方法this.msgchild.randomMsg(); } } }};</script><style lang='scss' scope>#chatdetail { position: relative; background-color: rgb(238, 212, 238); .chattop { position: fixed; top: 0; left: 0; z-index: 10; width: 100%; height: 3.5rem; line-height: 3.5rem; background-color: rgb(240, 240, 240) !important; display: flex; flex-direction: row; .chattop_back { flex: 1; margin-left: 1rem; } .chattop_name { flex: 20; text-align: center; } .chattop_more { flex: 1; margin-right: 1rem; } } .chatcontent { width: 100%; height: 100%; } .chatfooter { position: fixed; left: 0; bottom: 0; z-index: 10; width: 100%; height: 3.5rem; line-height: 3.5rem; text-align: center; background-color: rgb(240, 240, 240) !important; display: flex; flex-direction: row; div:nth-child(1), div:nth-child(3), div:nth-child(4) { flex: 1; svg {font-size: 1.5rem;margin-top: 0.9rem; } } div:nth-child(2) { flex: 5; input {width: 100%;height: 2.5rem;outline: none;padding-left: 0.5rem;box-sizing: border-box;height: 2.5rem;margin-top: 0.5rem;border-style: none;font-size: 0.9rem;border-radius: 4px;background-color: #fff;color: #000; } } }}</style>

ChatMsg.vue:

<template> <div ref='msg'> <!-- 動態創建 --> <div v-for='(item,index) in lists' :key='index'> <div v-if='item.id==122' class='user'><div v-scroll> <img :src='http://www.b3g6.com/bcjs/item.face' alt /> <div class='bubble'> <span>{{item.word}}</span> </div></div> </div> <div v-if='item.id==1529' class='touser'><div v-scroll> <img :src='http://www.b3g6.com/bcjs/item.face' alt /> <div class='tobubble'> <span>{{item.word}}</span> </div></div> </div> </div> </div></template><script>import userinfo from './userinfo';export default { name: 'ChatMsg', data() { return { userimg: '', lists: [] }; }, mounted() { this.userid = userinfo.id; this.userimg = userinfo.imgurl; }, // vue自動滾動到底部 directives: { scroll: { inserted(el) {el.scrollIntoView(); } } }, methods: { saveMsg(tomsg) { this.lists.push({id: this.userid,face: this.userimg,word: tomsg }); }, randomMsg() { let touserdata = userinfo.data; this.lists.push({id: touserdata.id,face: touserdata.imgurl,word: touserdata.words[Math.floor(Math.random() * touserdata.words.length)] .info }); } }};</script><style lang='scss' scope>#chatmsg { position: relative; top: 3.5rem; width: 100%; min-height: 44rem; background-color: rgb(238, 212, 238); margin-bottom: 3.5rem; overflow-x: hidden; overflow-y: auto; .user { position: relative; width: 100%; overflow: hidden; margin: 0.8rem 0; img { object-fit: cover; width: 3rem; height: 3rem; border-radius: 3px; float: right; margin-right: 1rem; } .bubble { position: relative; float: right; margin-right: 1rem; padding: 0.8rem; box-sizing: border-box; border-radius: 3px; max-width: 65%; background-color: rgb(116, 228, 116); span {height: 1.25rem;line-height: 1.25rem; } } .bubble::after { position: absolute; right: -1.3rem; top: 0.8rem; content: ''; width: 0; height: 0; border: 0.7rem solid; border-color: transparent transparent transparent rgb(116, 228, 116); } } .touser { position: relative; width: 100%; overflow: hidden; margin: 0.8rem 0; img { object-fit: cover; width: 3rem; height: 3rem; border-radius: 3px; float: left; margin-left: 1rem; } .tobubble { position: relative; float: left; margin-left: 1rem; padding: 0 0.7rem; box-sizing: border-box; border-radius: 3px; max-width: 65%; background-color: rgb(116, 228, 116); line-height: 3rem; } .tobubble::after { position: absolute; left: -1.3rem; top: 0.8rem; content: ''; width: 0; height: 0; border: 0.7rem solid; border-color: transparent rgb(116, 228, 116) transparent transparent; } }}</style>

3.目錄結構

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲伊人影院| 国产成人精品一区二区三区在线| 免费日韩视频| 美女视频免费精品| 日本欧美在线| 91午夜精品| 亚洲影院天堂中文av色| 国产精品99一区二区| 91成人精品在线| 天堂成人免费av电影一区| 久久国产日本精品| 中文视频一区| 亚洲精选av| 激情综合网站| 日韩天堂av| 亚洲欧洲午夜| 中文日韩在线| 国产一区视频在线观看免费| 欧洲av一区二区| 91精品国产福利在线观看麻豆| 国产精品免费大片| 久久精品超碰| 乱一区二区av| 日韩国产一区二区| 欧美综合另类| 日韩精品一卡二卡三卡四卡无卡| 国产精品密蕾丝视频下载| 亚洲欧美日本视频在线观看| 天堂成人国产精品一区| 日韩精品免费观看视频| 国产精品一级在线观看| 国产一区二区三区免费在线| 影院欧美亚洲| 欧美一级全黄| 亚洲成a人片| 日韩中文字幕1| 国产精品扒开腿做爽爽爽软件| 精品网站999| 99成人在线视频| 日韩国产欧美在线视频| 精品三级国产| 亚洲伦乱视频| 久久人人99| 国产精品白丝一区二区三区| 91精品国产调教在线观看| 欧美一级二区| 亚洲精品电影| 国产精品成人a在线观看| 丝袜美腿亚洲一区二区图片| 久久精品免视看国产成人| av不卡免费看| 精品亚洲成人| 日韩精品一区二区三区中文| 日韩成人综合| 久久精品日韩欧美| 亚洲日本久久| 欧美国产一级| 国产香蕉精品| 免费一级片91| 欧美日韩视频网站| 国产精品一区免费在线| 日韩有码av| 免费在线观看视频一区| 怡红院精品视频在线观看极品| 久久精品伊人| 国产999精品在线观看| 日韩成人av影视| 中文字幕日韩亚洲| 免播放器亚洲| 九一成人免费视频| 激情久久久久久| 精品国产乱码久久久| 日韩激情综合| 日韩区一区二| 日本不卡高清| 日本午夜精品久久久久| 亚洲青青久久| 一级欧美视频| 蜜芽一区二区三区| 中文一区一区三区免费在线观| 亚洲激情另类| 91久久中文| 在线观看一区| 日韩中文字幕| 国产精品最新| 久久精品99国产精品| 日韩国产欧美在线播放| 国产精一区二区| 国产粉嫩在线观看| 日韩午夜av在线| 亚洲精品乱码日韩| 国产欧美大片| 日韩不卡免费高清视频| 99视频一区| 亚洲欧美在线综合| 日韩精品亚洲专区| 欧美国产极品| 91亚洲一区| 日韩专区一卡二卡| 91成人精品在线| 色婷婷久久久| 狠狠爱www人成狠狠爱综合网| 免费在线观看日韩欧美| 亚洲午夜久久| 亚洲国产成人二区| 久久国产精品亚洲77777| 国产精品亚洲欧美| 不卡福利视频| 综合日韩在线| 成人日韩在线观看| 免费看欧美美女黄的网站| 国产精品调教| 欧美精品一二| 欧美aa在线视频| 在线亚洲自拍| 久久久久免费| 亚洲一区av| 国产麻豆久久| 国产精品视频3p| 中文视频一区| 欧美特黄一区| 日韩伦理在线一区| 奇米亚洲欧美| 老鸭窝亚洲一区二区三区| 91嫩草亚洲精品| 国产三级一区| 日韩精品一区二区三区中文在线 | 日韩欧美高清一区二区三区| 麻豆精品国产91久久久久久| 亚洲一区黄色| 久久高清精品| 福利在线一区| 欧美亚洲色图校园春色| 蜜臀av性久久久久蜜臀aⅴ流畅| 国产99久久| 精品女同一区二区三区在线观看| 日韩在线网址| 麻豆精品蜜桃| 免费视频亚洲| 激情久久久久久久| 国产综合激情| 国产精品免费看| 欧美日韩视频免费观看| 高清av一区| 久久国产影院| 久久蜜桃精品| 极品日韩av| 亚洲视频国产精品| 欧美一区网站| 精品视频在线你懂得| 国产精品多人| 麻豆视频在线看| 亚洲天堂久久| 影音国产精品| 亚洲三级毛片| 久久影院一区二区三区| 精品国产精品国产偷麻豆 | 欧洲av不卡| 久久久久.com| 久久亚洲不卡| 欧美日本三区| 综合日韩av| 久久福利一区| 久久国产精品色av免费看| 天堂√8在线中文| 日韩在线卡一卡二| 国产精品99久久久久久董美香| 久久久精品久久久久久96 | 欧美日韩国产高清电影| 色老板在线视频一区二区| 一区二区精品| 国产高清不卡| 日本中文字幕不卡| 久久久久美女| 欧美交a欧美精品喷水| 99精品99| 久久国际精品| 亚洲高清不卡| 国产一区二区三区久久| 爽爽淫人综合网网站| 久久字幕精品一区| 99国产一区| 国产麻豆精品| 奶水喷射视频一区| 人人精品亚洲| 里番精品3d一二三区| 午夜电影一区| 在线视频精品| 亚洲小说欧美另类婷婷| 精品伊人久久久| 日韩精品91亚洲二区在线观看| 国产精品毛片一区二区三区| 成人午夜网址| 国产成人免费精品| 国产在视频一区二区三区吞精| 国产欧美啪啪| 日本不卡一二三区黄网| 午夜在线播放视频欧美| 亚洲女同中文字幕| 五月天激情综合网|