vue聊天功能

<template>

<div class="hellos" style="overflow: auto;">

<ul class="list">

<li :class="{back:token==item.userInfo.user_id}" v-for="item in list">

<p class="myimg"><img :src="item.userInfo.avatar"/></p>

<p class="myname">{{item.userInfo.user_name}}</p>

<p class="mytext">{{item.msg}}</p>

</li>

</ul>

<van-cell-group>

<van-field v-model="value" placeholder="请输入用户名" @keyup.enter="sendouts"/>

<van-button type="info" @click="sendout">信息按钮</van-button>

</van-cell-group>

</div>

</template>

<script>

import io from "socket.io-client"

import qs from 'qs'

import cookies from 'js-cookie'

import { Toast } from 'vant'

export default {

name: 'HelloWorld',

data() {

return {

value: "",

socket:{},

list:[],

userInfo:{},

token:""

}

},

created(){

this.token =cookies.get('token')

this.getUserInfo()

this.socket=io('ws://47.95.110.109:8000/')

this.socket.on('res',(data)=>{

this.list.push(data)

})

},

methods:{

sendout(){

if(this.value===""){

Toast("输入不能为空")

}else{

this.socket.emit('all',{

msg:this.value,

userInfo:this.userInfo

})

this.value=""

}

},

sendouts(){

this.sendout()

},

getUserInfo(){

var url = "http://api.baxiaobu.com/index.php/home/v1/getUserInfo";

var params = {

user_id:this.token

}

params=qs.stringify(params)

this.axios.post(url,params).then((res)=>{

this.userInfo=res.data.userInfo

})

}

}

}

</script>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 网络编程 一.楔子 你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运...
    go以恒阅读 6,459评论 0 6
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 7,931评论 0 3
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 6,187评论 0 2
  • test 真的好
    e2ae7303450b阅读 1,193评论 1 1
  • 每年不管我回几次家,大聚会总是会组织一场,今年照例。 吃的还是家乡的老火锅,这个老火锅和现在的成都重庆火锅截然不同...
    至尊龙女阅读 3,034评论 1 14

友情链接更多精彩内容