修改用户信息功能图片无法回显,并且报错,如何修改,数据库中只存了一张图片,并且是字符串格式,我希望可以回显图片,并且具有修改功能。
<template>
<topview message="修改个人信息"></topview>
<div>
<div style="
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 10px;
">
<van-form @submit="onSubmit">
<div>
</div>
<van-cell-group inset>
<van-field v-model="userinfo.userName" name="用户名" label="用户名" placeholder="用户名"
:rules="[{ required: true, message: '请填写用户名' }]" />
<van-field v-model="userinfo.userPassword" type="password" name="密码" label="密 码" placeholder="密码"
:rules="[{ required: true, message: '请填写密码' }]" />
<van-field v-model="userinfo.userPhone" type="text" name="手机号" label="手机号" placeholder="手机号"
:rules="[{ required: true, message: '请填写手机号' }]" />
<van-field v-model="userinfo.userNickname" type="text" name="昵称" label="昵称" placeholder="昵称"
:rules="[{ required: true, message: '请填写昵称' }]" />
<van-field name="userSex" label="性别:">
<template #input>
<van-radio-group v-model="userinfo.userSex" direction="horizontal">
<van-radio name="男">男</van-radio>
<van-radio name="女">女</van-radio>
</van-radio-group>
</template>
</van-field>
<van-field v-model="userinfo.userUsername" type="text" name="身份证" label="身份证" placeholder="身份证"
:rules="[{ required: true, message: '请填写身份证' }]" />
<img :src="userinfo.userPic" alt="User Avatar" class="photo1" v-if="userinfo.userPic" />
<van-field name="userPic" label="头像上传">
<template #input>
<van-uploader v-model="userinfo.userPic" :after-read="afterRead" :max-count="1" />
</template>
</van-field>
</van-cell-group>
<div style="margin: 16px">
<van-button round block type="primary" native-type="submit">
修改
</van-button>
</div>
</van-form>
</div>
</div>
</template>
<script setup>
import topview from '@/components/topView.vue';
import { ref, reactive, onMounted } from "vue";
import { getUserApi,editUserApi } from "@/api";
import { useCounterStore } from "@/stores/counter";
import { useRouter } from "vue-router";
//返回
const backbtn = () => {
window.history.back();
};
//上传图片
const afterRead = () => {
};
const store = useCounterStore();
const router = useRouter();
const userinfo = ref({});
//用户信息回显
const getUser = async (e) => {
const res = await getUserApi(e);
userinfo.value = res.data;
console.log('用户信息查询',userinfo.value)
};
onMounted(() => {
getUser(store.userInfo.userId);
});
</script>
<style scoped>
.photo1 {
width: 100px;
height: 100px;
border-radius: 50px
}
</style>