Vue 移动端 实战九 编辑用户资料、修改呢称、生日、性别、头像、以及头像的剪裁器依赖使用、Content-Type 要求的 multipart/form-data 格式

编辑用户资料

1.0 创建组件并配置路由

1、创建 views/user/index.vue

<template>
  <div>
    <van-nav-bar title="个人信息" left-arrow right-text="保存" />
    <van-cell-group>
      <van-cell title="头像" is-link>
        <van-image
          round
          width="30"
          height="30"
          fit="cover"
          src="http://toutiao.meiduo.site/FgSTA3msGyxp5-Oufnm5c0kjVgW7"
        />
      </van-cell>
      <van-cell title="昵称" value="abc" is-link />
      <van-cell title="性别" value="男" is-link />
      <van-cell title="生日" value="2019-9-27" is-link />
    </van-cell-group>
  </div>
</template>

<script>
  export default {
   
    name: "UserIndex"
  };
</script>

2、将该页面配置到根路由

{
   
  name: 'user-profile',
  path: '/user/profile',
  component: () => import('@/views/user-profile')
}

2.0 页面布局

<template>
  <div class="user-profile">
    <!-- 导航栏 -->
    <van-nav-bar
      class="page-nav-bar"
      title="个人信息"
      left-arrow
      @click-left="$router.back()"
    />
    <!-- /导航栏 -->

    <!-- 个人信息 -->
    <van-cell class="avatar-cell" title="头像" is-link center>
      <van-image
        class="avatar"
        round
        fit="cover"
        src="https://img.yzcdn.cn/vant/cat.jpeg"
      />
    </van-cell>
    <van-cell title="昵称" value="内容" is-link />
    <van-cell title="性别" value="内容" is-link />
    <van-cell title="生日" value="内容" is-link />
    <!-- /个人信息 -->
  </div>
</template>

<script>
export default {
   
  name: 'UserProfile',
  components: {
   },
  props: {
   },
  data () {
   
    return {
   }
  },
  computed: {
   },
  watch: {
   },
  created () {
   },
  mounted () {
   },
  methods: {
   }
}
</script>

<style scoped lang="less">
.user-profile {
   
  .avatar-cell {
   
    .van-cell__value {
   
      display: flex;
      flex-direction: row-reverse;
    }
    .avatar {
   
      width: 60px;
      height: 60px;
    }
  }
}
</style>

3.0 展示用户信息

思路:

  • 找到数据接口
  • 封装请求方法
  • 请求获取数据
  • 模板绑定

1、在 api/user.js 中添加封装数据接口

/**
 * 获取当前登录用户的个人资料
 */
export const getUserProfile = target => {
   
    return request({
   
        method: 'GET',
        url: '/app/v1_0/user/profile'
    })
}

2、在 views/user/index.vue 组件中请求获取数据

import {
    getUserProfile } from '@/api/user'

  created () {
   
    this.loadGetUserProfile()
  },
 methods: {
   
    async loadGetUserProfile() {
   
      try {
   
        const {
    data } = await getUserProfile()
        this.user = data.data
      } catch (err) {
   
        this.$toast('获取数据失败')
      }
    }
  }
    <van-cell class="avatar-cell" title="头像" is-link center>
      <van-image
        class="avatar"
        round
        fit="cover"
        :src="user.photo"
      />
    </van-cell>
    <van-cell title="昵称" :value="user.name" is-link />
    <van-cell title="性别" :value="user.gender === 0 ? '男' : '女'" is-link />
    <van-cell title="生日" :value="user.birthday" is-link />

4.0 修改昵称

一、准备弹出层

<van-cell title="昵称" :value="user .name" is-link @click="isUpdateNameShow = true"/>

    <!-- 修改名称弹出层 -->
    <van-popup v-model="isUpdateNameShow" position="bottom" style="height: 100%">
      <update-name 
      v-if="isUpdateNameShow"
       @close="isUpdateNameShow = false"
       v-model="user.name"
      ></update-name>
    </van-popup>

二、封装组件

<template>
  <div class="update-name">
    <!-- 导航栏 -->
    <van-nav
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue移动中,有多个富文本编辑可供选择。其中一些优秀的富文本编辑包括UEditor、wangEditor和vue-html5-editor。这些编辑具有丰富的功能和良好的表现。另外,还有一些备选的编辑,如vue-quill-editor和tinymce,可以根据需求进行选择和使用。对于Vue移动中富文本编辑使用以及常见问题的处理,你可以参考vue-html5-editor组件的文档和相关资料。通过使用这些富文本编辑,你可以方便地实现在Vue移动编辑富文本内容的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [基于 Vue移动富文本编辑 vue-quill-editor 实战](https://blog.csdn.net/weixin_34320724/article/details/91383543)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [工作笔记四——vueJS在移动使用富文本编辑](https://blog.csdn.net/weixin_30649641/article/details/99472504)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值