美文网首页测试员的那点事
vue-微信聊天界面(一)

vue-微信聊天界面(一)

作者: 望月成三人 | 来源:发表于2020-11-08 16:26 被阅读0次
  • 经过前面的基础学习,现在开始学习使用脚手架
  • 本节目标界面如下


    image.png
  • 点击右侧用户列表,左侧聊天界面展示用户名

分析

  • 左右两侧分别作为组件

环境准备

  • 创建项目vue create wechat

代码展示

  • app.vue主界面
<template>
  <div id="app">
    <h1>{{msg}}</h1>
    <div class="content">
        <chat-window :currentUser="currentUser"></chat-window>
        // 父组件监控子组件的自定义方法是chooseuser,并触发父元素的toggleUser方法,父元素的这个方法主要是把点击的用户列表数据传给子元素chatWindow组件
        <user-list :userlistdata="userlistdata" @chooseuser="toggleUser"></user-list>
    </div>
  </div>
</template>

<script>
// 引用左右两个组件
import ChatWindow from './components/ChatWindow.vue'
import UserList from './components/UserList.vue'

export default {
  name: 'App',
   // 注册组件
  components: {
    UserList,ChatWindow
  },
  data() {
    return {
      msg: "我的聊天室",
       // 用户列表的数据,传给userlist组件
      userlistdata: [
          {"username": "小明", "headimg": require("./assets/images/1.jpg")},
          {"username": "小红", "headimg": require("./assets/images/2.jpg")},
          {"username": "小黑", "headimg": require("./assets/images/3.jpg")}
      ],
      // 当前用户在聊天左侧界面展示的默认数据,传给chatWindow组件
      currentUser: {
        "username": "小明", "headimg": require("./assets/images/1.jpg")
      }
    }
  },
  methods:{
      toggleUser:function(index){
        this.currentUser = this.userlistdata[index]
    }
  }
}
</script>

<style>
.content {
  width: 800px;
  height: 700px;
  display: flex;
  margin: 0 auto;
  border: 1px solid #cccccc;

}
</style>

  • src/components/UserList.vue用户列表组件
<template>
    <div class="userlist">
        <h3>用户列表</h3>
        <ul>
          <!-- userlistdata是父元素传过来的列表数据,接受需要设置props -->
            <li v-for="(item,index) in userlistdata" :key="'userlistdata'+ index" @click="chooseuser(index)">
                <img :src="item.headimg">
                <h4>{{item.username}}</h4>
            </li>
        </ul>
    </div>
</template>
<style scoped>
    .userlist {
        width: 300px;
        height: 700px;
        background: skyblue;
    }
    .userlist ul li {
        display: flex;
    }
    .userlist ul li img {
        width: 80px;
        height: 80px;
    }
</style>
<script>
export default {
    data(){
        return {}
    },
// 接受父元素传过来的用列表数据
    props:["userlistdata"],
    methods:{
        chooseuser:function(index) {
            // 将选择用户事件传给父元素
            this.$emit("chooseuser", index)
        }
    }
}
</script>
  • src/components/ChatWindow.vue左侧的聊天记录展示组件
<template>
    <div class="chat">
        <h3>用户聊天界面</h3>
        <p>用户:{{currentUser.username}}</p>
    </div>
</template>

<style scoped>
    .chat 
    {
        width: 500px;
    }

</style>


<script>
export default {
    data() {
        return {}
    },
    props:["currentUser"]
}
</script>

相关文章

  • vue-微信聊天界面(一)

    经过前面的基础学习,现在开始学习使用脚手架 本节目标界面如下image.png 点击右侧用户列表,左侧聊天界面展示...

  • vue-微信聊天界面(二)

    上编[https://www.jianshu.com/p/76ae4cd1dfc5]是微信界面(一),界面如下im...

  • html5仿微信web版|仿微信客户端聊天

    h5仿微信实战项目|仿微信web端聊天界面|仿微信电脑端界面 之前做了一个手机端 h5仿微信聊天 界面,最近又开发...

  • iXShot样张

    测试机型iPhone SE 1.微信朋友圈支持朋友圈界面的拼接 2.微信好友列表 3.微信聊天界面2 4.微信聊天...

  • 微信小助手

    批量添加标签 微信聊天界面,点击内容,选择更多,选中同类标签内容,标注标签。 常用微信功能界面 聊天文件查找 设为...

  • 微信搜索长按文字方案

    微信聊天界面长按文字搜索方案 一、当前版本概况 当前版本的微信版本在聊天界面不能长按文字直接对文字进行搜索的功能。...

  • iOS类似微信聊天界面时间转换

    iOS类似微信聊天界面时间转换 下面这个大家不用看,仅供参考,类似微信聊天界面每隔5分钟显示一次时间

  • 微信聊天界面分析

    一直以来,用我们的app聊天有种奇怪的感觉,但具体哪里奇怪,也说不上来。直到开发iPad版,遇到各种问题,仔细研究...

  • 微信界面

    随着微信的普及,微信聊天也成为了人们每天必不可少的活动。打开微信首先引入眼帘的是微信聊天界面,而每个人也有着自己的...

  • h5聊天室weChatRoom|仿微信群聊天室(多人聊天)

    html5+css3聊天室实战开发|h5仿微信聊天室界面|仿微信群聊/单聊 这个项目是利用h5开发的仿微信聊天室,...

网友评论

    本文标题:vue-微信聊天界面(一)

    本文链接:https://www.haomeiwen.com/subject/jtehbktx.html