成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

Vue實現(xiàn)聊天界面

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

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

1.功能需求

根據(jù)索引選擇跟不同的人進行聊天

Vue實現(xiàn)聊天界面

Vue實現(xiàn)聊天界面

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:'我發(fā)現(xiàn)我真的是宅女'}, {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)'; // 動態(tài)dom元素渲染完成之后,跳轉(zhuǎn)到另一個界面(ChatDetail) // 獲取動態(tài)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.piao2010.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 = ''; } }, // 發(fā)送消息 sendmsg(e) { // 1、用ref定義輸入回復(fù)內(nèi)容的input文本框,定義sendcontent變量接收其value值(輸入的內(nèi)容) 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、調(diào)子組件里的方法,并將tomsg傳到ChatMsg(子)組件(具體的聊天內(nèi)容)中this.msgchild.saveMsg(this.tomsg);// 5、發(fā)送完一條信息之后,需清空文本框this.$refs.sendcontent.value = '';// 回車時,調(diào)用子組件的隨機消息的方法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'> <!-- 動態(tài)創(chuàng)建 --> <div v-for='(item,index) in lists' :key='index'> <div v-if='item.id==122' class='user'><div v-scroll> <img :src='http://www.piao2010.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.piao2010.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.目錄結(jié)構(gòu)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久
日本中文字幕一区二区视频 | 久久久久久黄| 国产欧美一区二区三区网站| 国产99久久久国产精品免费看| 欧美午夜免费电影| 青娱乐精品在线视频| 久久精品日韩| 亚洲国产人成综合网站| 亚洲第一在线| 亚洲国产成人一区二区三区| 91免费版pro下载短视频| 日韩欧美国产综合一区| 国产在线精品不卡| 欧美日韩国产高清一区二区| 麻豆国产精品官网| 在线观看视频一区| 日韩av电影免费观看高清完整版| 西西裸体人体做爰大胆久久久| 一区二区欧美在线观看| 亚洲国产清纯| 亚洲色大成网站www久久九九| 欧美婷婷在线| 亚洲国产精品激情在线观看| 欧美有码视频| 久久久综合九色合综国产精品| 成人综合激情网| 日韩美女视频在线| 92精品国产成人观看免费| 久久久久国产精品厨房| 色综合中文字幕国产 | 欧美精品一二三区| 国产一区二区三区香蕉| 欧美一级日韩免费不卡| 成人激情动漫在线观看| 日韩一区二区在线看| 风流少妇一区二区| 欧美电影免费观看高清完整版在线 | 国内揄拍国内精品久久| 亚洲欧洲性图库| 亚洲精品在线免费| 亚洲成人你懂的| 欧洲激情一区二区| 国产成人免费在线视频| 欧美成人精品3d动漫h| 91最新地址在线播放| 国产欧美日韩视频一区二区| 午夜日韩激情| 亚洲欧美日韩久久| 小嫩嫩精品导航| 日av在线不卡| 欧美日韩久久一区二区| 国产精品自拍在线| 国产亚洲女人久久久久毛片| 激情欧美亚洲| 日韩电影在线一区二区三区| 欧美一区日韩一区| 国产在线日韩| 日本欧美加勒比视频| 日韩欧美一区中文| 一区精品久久| 日本 国产 欧美色综合| 日韩精品中文字幕在线一区| 欧美日韩一区在线播放 | 国产.欧美.日韩| 国产精品美女久久久久久久| 国产精品日本欧美一区二区三区| 麻豆国产精品视频| 精品处破学生在线二十三| 亚洲调教视频在线观看| 亚洲一级二级三级| 欧美三级中文字| 99精品久久免费看蜜臀剧情介绍| 国产欧美1区2区3区| 国产农村妇女精品一二区| 久久精品国产成人一区二区三区 | 久久综合色播五月| 国产伦精品一区二区三区四区免费| 麻豆91精品视频| 久久久久国色av免费看影院| 国产亚洲激情| 国产福利一区二区| 亚洲欧美一区二区不卡| 欧美在线不卡一区| 国产成人午夜高潮毛片| 中文字幕乱码亚洲精品一区| 国产美女精品| 成人午夜av电影| 亚洲精品中文在线观看| 欧美精品久久久久久久久老牛影院| 欧美午夜在线| 精品亚洲欧美一区| 亚洲精品乱码久久久久久| 欧美一级高清片| 国产亚洲在线| 风流少妇一区二区| 一区二区高清视频在线观看| 555www色欧美视频| 亚洲日本黄色| 国产一区二区视频在线| 亚洲欧美日韩综合aⅴ视频| 欧美午夜电影在线播放| 欧美日本一区| 久久国产精品第一页| 国产性色一区二区| 欧美日韩精品综合在线| 99视频日韩| www.久久精品| 视频一区欧美日韩| 久久精品视频免费| 欧美亚洲国产一区二区三区| 欧美精品日本| 国产美女精品一区二区三区| 亚洲精品成人悠悠色影视| 精品国产一区二区精华| 色一情一乱一乱一91av| 欧美成人69av| 国产在线精品不卡| 亚洲国产精品久久久男人的天堂| 久久久噜噜噜久久中文字幕色伊伊 | 欧美久久久久久久| 国产一区二区三区视频在线播放| 亚洲激情av在线| 久久影音资源网| 欧美日韩免费观看一区二区三区| 91久久精品www人人做人人爽| 丰满岳乱妇一区二区三区| 香蕉av福利精品导航| 国产精品欧美一级免费| 欧美日韩在线播放| 99riav1国产精品视频| 成人综合婷婷国产精品久久免费| 亚洲成人免费影院| 国产精品久久毛片av大全日韩| 日韩欧美国产成人一区二区| 91国产精品成人| 在线亚洲自拍| 欧美日韩99| 国产不卡免费视频| 琪琪一区二区三区| 亚洲中国最大av网站| 国产欧美久久久精品影院| 91精品国产综合久久久久久漫画| 国产嫩草一区二区三区在线观看| 91香蕉视频污在线| 国产乱子轮精品视频| 视频在线观看一区二区三区| 一区二区三区色| 中文字幕一区二区三区视频| 精品美女一区二区三区| 欧美午夜一区二区三区免费大片| 一区二区国产日产| 欧美精品黄色| av在线播放一区二区三区| 国内精品伊人久久久久影院对白| 亚洲v中文字幕| 一区二区在线观看免费视频播放| 欧美国产日韩在线观看| 精品国产乱码久久久久久浪潮 | 亚洲精品高清视频在线观看| 国产欧美日韩三区| 精品久久久三级丝袜| 欧美精品久久99久久在免费线| 色视频欧美一区二区三区| 国产精品一区亚洲| 亚洲深夜av| 夜久久久久久| 亚洲承认在线| 在线看片一区| 国产精品分类| 你懂的网址国产 欧美| heyzo一本久久综合| 国产91精品久久久久久久网曝门 | 欧美区一区二| 欧美日本二区| 欧美日韩1080p| 欧美另类亚洲| 国产精品成人观看视频免费| 欧美日韩mv| 欧美成人在线免费观看| 色综合色综合色综合| 99r精品视频| 国产精品va| 永久域名在线精品| 韩国免费一区| 亚洲成人自拍视频| 最新国产乱人伦偷精品免费网站| 黄色av成人| 好吊一区二区三区| 欧美日韩免费高清| 亚洲无线观看| 亚洲精品一区二区三区樱花| 亚洲人成网站在线观看播放| 国产精品毛片| 久久久www| 欧美色综合天天久久综合精品| 欧美日韩一区精品| 3d成人h动漫网站入口| 欧美成人女星排行榜| 久久久综合视频| 国产精品久久久久久久久快鸭|