什么是“&”在“&.sub-title”中是否表示在scss中?

文章探讨了在SCSS中`&`符号的用法,如何在`.title`类内嵌套`.sub-title`,以及`&`如何帮助创建选择器`.title.sub-title`。当`&`省略时,选择器的行为会有所不同,影响匹配的元素。对于CSS新手,理解这一点至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何解决什么是“&”在“&.sub-title”中是否表示在scss中??
该&串接的父类,从而导致.title.sub-title(而不是.title .sub-title如果&被省略)。

结果是,与&匹配的元素与title和sub-title类都匹配:

而如果没有,&它将匹配具有class sub-title的元素class 的后代title:
...
...
解决方法 我是CSS和SCSS的新手。

在以下代码中,

.title {
width: 718px;
&.sub-title {
width: 938px;
}
}
什么是 &。 手段?和嵌套类一样吗?

声明:地推任务网所有作品(图片、文字)均由用户自行上传分享,仅供网友学习交流。

.el-menu--horizontal .el-menu-item.is-active, .el-submenu.is-active .el-submenu__title { background: #7eb63b !important; /* 设置激活背景颜色 */ color: white !important; /* 设置激活文本颜色 */ } /* 悬停状态的样式 */ .el-menu-item:hover, .el-submenu__title:hover { background: rgb(41, 41, 41); /* 设置悬停背景颜色 */ } /* 确保二级菜单头部在激活时有背景色 */ .el-submenu__title.is-active { background: #7eb63b !important; /* 设置激活背景颜色 */ color: white !important; /* 设置激活文本颜色 */ } // 背景透明 .el-menu-demo { background: transparent; } // 去除自带的底部border .el-menu.el-menu--horizontal { border: none; } // 更改鼠标划过背景色字体色及borer显示 .el-menu--horizontal ::v-deep.el-menu-item:not(.is-disabled):hover { background:transparent !important; color: #fff; border-bottom: 1px solid #fff !important; } /* 全局样式(无scoped) */ .el-menu--horizontal .el-submenu .el-menu-item.is-active { background-color: #ffd04b !important; } /* 组件内样式(带scoped时需穿透) */ ::v-deep .el-menu--horizontal .el-submenu .el-menu-item.is-active { background-color: #ffd04b; }/* 一级菜单项和二级菜单项的公共样式 */ .el-menu-item, .el-submenu__title { width: auto; /* 自适应宽度 */ min-width: 150px; /* 设置最小宽度,防止过窄 */ text-align: center; /* 确保文本居中 */ display: flex; align-items: center; justify-content: center; height: 100%; } /* 二级菜单的样式 */ .el-submenu .el-menu { width: 100%; /* 确保子菜单宽度与父菜单项一致 */ position: absolute; /* 确保子菜单绝对定位 */ left: 0; /* 确保子菜单与父菜单项对齐 */ min-width: 100%; /* 确保子菜单宽度至少与父菜单项一致 */ } /* 水平菜单的一级菜单项和二级菜单项的公共样式 */ .el-menu--horizontal > .el-menu-item, .el-menu--horizontal > .el-submenu { display: flex; align-items: center; justify-content: center; height: 100%; min-width: 150px; /* 设置最小宽度,防止过窄 */ flex: 1; } <el-menu background-color="#333" text-color="#fff" :default-active="activeIndex" class="el-menu-demo" mode="horizontal" router style="list-style: square !important; height: 100%;" >请看我给你的代码
03-24
<template> <div :class="['page-layout', wrapClass, isDark && 'theme-dark']"> <div :class="['page-layout--placeholer', breadMenuHidden && 'no-nav']"></div> <TopHeader class="page-layout__header" /> <SideBar :menus class="page-layout__side" /> <div :class="['page-layout__main', { 'no-nav': breadMenuHidden }]"> <div v-if="!breadMenuHidden" class="page-layout__main-nav" > <BreadMenu /> </div> <div class="page-layout__main-view" :class="{ 'is-mobile': appStore.$state.isMobile }" > <div v-if="pageTitle.visible" class="page-layout__main-view-title common-page-title" > <span> {{ pageTitle.label }}</span> <a-button v-if="route?.meta?.backBtn" type="primary" @click="handleBack" >{{ btnLabel }}</a-button > </div> <RouterView v-slot="{ Component }"> <KeepAlive :include="cacheViews"> <component :is="Component" :key="routeKey" /> </KeepAlive> </RouterView> </div> <!-- TODO: 底部有固定定位元素<MainFixedBar />时占位用 勿删! --> <div class="page-bar__fixed-placeholer"></div> </div> </div> </template> <script setup lang="ts"> import { computed, onMounted, ref, h, watchEffect, watch, nextTick } from "vue" import { useAppStore, useMsgStore, useUserStore, useSysConfigStore } from "@/stores" import TopHeader from "./components/TopHeader.vue" import SideBar from "./components/side-bar/index.vue" import BreadMenu from "./components/BreadMenu.vue" import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router" import { Button, Notification, type NotificationReturn } from "@arco-design/web-vue" import type { RecordModel as MessageData } from "@/api/message/api-type" import { IconRight } from "@arco-design/web-vue/es/icon" import { ORDER_TRANSFER } from "@/router/order" import { getSystemConfig } from "@/api/system/index.serv" import { to } from "await-to-js" defineOptions({ name: "Layout" }) const route = useRoute() const router = useRouter() const appStore = useAppStore() const userStore = useUserStore() const msgStore = useMsgStore() const sysConfigStore = useSysConfigStore() const orderMsgReturn = ref<NotificationReturn>() const breadMenuHidden = ref(false) const btnLabel = computed(() => { return window.opener ? "关闭" : route?.meta.backBtn?.label || "关闭" }) const cacheViews = computed(() => appStore.routeViewCache) const msgId = computed(() => msgStore.msgNoticeId) const pageTitle = computed(() => { const { navTitle, title, titleVisible } = route.meta ?? {} return { visible: title && titleVisible !== false, label: navTitle || title } }) const routeKey = computed(() => { const { name, query = {} } = route if (Object.keys(query).length) { return `${name as string}-${JSON.stringify(route.query)}` } return name as string }) const wrapClass = computed(() => { return appStore.menuStatus ? "menu-collapse" : "menu-expend" }) const isDark = computed(() => appStore.theme === "dark") const menus = computed(() => userStore.accessMenu ?? []) const menuMap = computed(() => userStore.accessMenuMap) const doOrderLoop = computed(() => { return [...menuMap.value.values()].some((list) => { const loopData = list?.meta?.doLoop if (!loopData) return false const { code, dependMenu } = loopData if (code === "order") { if (!dependMenu) return true return menuMap.value.has(dependMenu) } else { return false } }) }) watchEffect(() => { breadMenuHidden.value = route.meta?.breadMenuVisible === false }) const goToTransfer = (data: MessageData) => { router .push({ name: ORDER_TRANSFER.name }) .then((res) => { Notification.remove(msgId.value) }) } const showOrderMsg = (data: MessageData) => { return Notification.info({ icon: () => h("span", { class: ["iconfont icon-file"] }), title: "您有一个订单需要进行调度", content: data.msg_body, id: msgId.value, closable: true, duration: 0, class: "order-msg__tip", position: "bottomRight", footer: () => h( Button, { type: "text", onClick: () => goToTransfer(data) }, ["立即前往", h(IconRight)] ) }) } watch( [() => msgStore.msgTargetId, () => sysConfigStore.orderMessageConfig.orderNoticeSwitch as number], async ([id, orderNoticeSwitch]: [number | undefined, number]) => { await nextTick() if (id && msgStore.unreadMsgLatest && orderNoticeSwitch === 1) { const msgReturn = showOrderMsg(msgStore.unreadMsgLatest) orderMsgReturn.value ||= msgReturn } else { Notification.remove(msgId.value) } }, { immediate: true } ) const handleBack = () => { if (window.opener) { window.close() } else { const routeTo = route.meta?.backBtn?.routeTo if (routeTo) { router.replace({ name: routeTo }) } } } onMounted(async () => { msgStore.clearLoopTimer() const [err, res] = await to(getSystemConfig()) if (!err && res) { sysConfigStore.setUpdateConfig({ id: res.data.id, orderNoticeSwitch: res.data.orderNoticeSwitch }) doOrderLoop.value && msgStore.messageAndCountLoop() } }) onBeforeRouteLeave(() => { Notification.remove(msgId.value) msgStore.clearLoopTimer() }) </script> <style lang="scss" scoped> @import "../assets/styles/mixin.scss"; $--layout-transition-all: all 0.2s cubic-bezier(0.34, 0.69, 0.1, 1); $--layout-transition-margin: margin 0.2s cubic-bezier(0.34, 0.69, 0.1, 1); $--layout-transition-left: left 0.2s cubic-bezier(0.34, 0.69, 0.1, 1); .page-layout { height: 100%; display: flex; flex-direction: column; overflow: hidden; &--placeholer { flex: none; height: calc(var(--page-header-height) + var(--page-breadmenu-height)); transition: none; &.no-nav { height: var(--page-header-height); } } &__header { position: fixed; top: 0; left: 0; right: 0; z-index: var(--page-max-z-index); flex: none; padding: 0 16px; height: var(--page-header-height); border-bottom: var(--color-border-2) 1px solid; background-color: #fff; transition: $--layout-transition-all; } &__side { position: fixed; z-index: var(--page-max-z-index); left: 0; top: var(--page-header-height); bottom: 0; display: flex; flex-direction: column; :deep(.arco-menu-inner) { flex: 1; margin-bottom: var(--menu-collapse-width); } :deep(.arco-menu-collapse-button) { position: absolute; } & + .page-layout__main { margin-left: var(--menu-expand-width); .page-layout__main-nav { left: var(--menu-expand-width); } } &.arco-menu-collapsed + .page-layout__main { margin-left: var(--menu-collapse-width); .page-layout__main-nav { left: var(--menu-collapse-width); } } } &__main { padding: var(--page-padding-gutter); padding-top: 0; transition: $--layout-transition-margin; height: 100%; display: flex; flex-direction: column; overflow-y: auto; @include scrollbar(8px, transparent, var(--color-fill-4)); &.no-nav { padding-top: var(--page-padding-gutter); } &-nav { flex: none; display: flex; align-items: center; background: var(--page-back-color); position: fixed; z-index: var(--page-max-z-index); top: var(--page-header-height); left: 0; right: 0; height: var(--page-breadmenu-height); padding: 0 var(--page-padding-gutter); transition: $--layout-transition-left; } &-content { position: relative; height: 100%; display: flex; flex-direction: column; padding: var(--page-padding-gutter); padding-top: --page-breadmenu-height; background: #f9f9f9; flex: 1; // margin-left: var(--menu-expand-width); // transition: margin-left 0.28s; // transition: all 0.2s cubic-bezier(0.34, 0.69, 0.1, 1); &.no-nav { padding-top: var(--page-padding-gutter); } } &-view { flex: 1; display: flex; flex-direction: column; background: #fff; border-radius: 4px; padding: var(--page-padding-gutter); // > :last-child:not(.common-page-title) { // flex: 1; // display: flex; // flex-direction: column; // } &-title { display: flex; justify-content: space-between; align-items: center; } } } &.theme-dark { .page-layout__header, .page-layout__side { background: var(--color-text-2); } } } </style> <style lang="scss"> .order-msg__tip { .arco-notification-title { font-weight: 600; } .arco-notification-left { padding-right: 5px; .arco-notification-icon { font-size: 16px; color: var(--color-text-2); } } .arco-notification-content { margin-top: 6px; } } </style>
06-26
<template> <view> <uni-card v-for="(comment, index) in finalResult" :key="index" title="obj.personName" sub-title="obj.remark" extra="额外信息" :thumbnail="avatar"> <text class="uni-body">姓名:{{obj.personName}}~户主或户主关系{{obj.relation}}~性别:{{obj.sex}}~民族:{{obj.nation}}~出生日期:{{obj.birthday}}~身份证件编号{{obj.id}}~籍贯:{{obj.nativeplace}}~文化程度:{{obj.education}}</text> <view class="action-container"> <button class="delete-button" @click="deleteComment(index)">删除</button> </view> </uni-card> <button class="delete-all-button" @click="deleteAllComments">删除所有评论</button> </view> </template> <script> export default { data() { return { finalResult: [], avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png' }; }, onShow() { this.finalResult = uni.getStorageSync("data") }, methods: { deleteAllComments() { // 清空 finalResult 数组 this.finalResult = []; // 清空存储中的评论数据 uni.clearStorageSync(); }, deleteComment(index) { // 根据索引从 finalResult 数组中删除评论 this.finalResult.splice(index, 1); // 获取指定评论的键名 let dataArray = uni.getStorageInfoSync(); let keyArray = dataArray.keys; let commentKey = keyArray[index]; // 从存储中删除指定评论数据 uni.removeStorageSync(commentKey); } } }; </script> <style lang="scss"> .action-container { display: flex; justify-content: flex-end; } .delete-button { background-color: #f00; color: #fff; border: none; padding: 5px 10px; margin-top: 5px; cursor: pointer; } .delete-all-button { background-color: #f00; color: #fff; border: none; padding: 10px; margin-top: 10px; cursor: pointer; } <style>这段代码有什么问题?
07-23
<template> <view class="user-center"> <!-- 头部导航 --> <view class="header"> <text class="title">个人中心</text> </view> <!-- 个人信息卡片 --> <view class="info-card"> <!-- 头像区域 --> <view class="info-item" @click="editAvatar"> <text class="label">头像</text> <view class="content"> <image :src="userInfo.avatar" class="avatar" mode="aspectFill" /> <text class="arrow">></text> </view> </view> <!-- 昵称区域 --> <view class="info-item" @click="editNickname"> <text class="label">昵称</text> <view class="content"> <text>{{ userInfo.nickname || '未设置' }}</text> <text class="arrow">></text> </view> </view> <!-- 性别区域 --> <view class="info-item" @click="editGender"> <text class="label">性别</text> <view class="content"> <text>{{ userInfo.gender || '未设置' }}</text> <text class="arrow">></text> </view> </view> <!-- 年龄区域 --> <view class="info-item" @click="editAge"> <text class="label">年龄</text> <view class="content"> <text>{{ userInfo.age || '未设置' }}</text> <text class="arrow">></text> </view> </view> </view> <!-- 退出登录按钮 --> <view class="logout-btn" @click="logout"> 退出登录 </view> <!-- 编辑弹窗 --> <view class="modal" v-if="showModal"> <view class="modal-content"> <view class="modal-header"> <text class="modal-title">{{ modalTitle }}</text> <text class="close" @click="closeModal">×</text> </view> <view class="modal-body"> <view v-if="modalType === 'avatar'"> <text>选择头像来源</text> <view class="avatar-options"> <view class="option" @click="chooseAvatar('camera')"> <image src="/static/camera.jpg" class="option-icon" mode="aspectFill" /> <text>拍照</text> </view> <view class="option" @click="chooseAvatar('album')"> <image src="/static/album.jpg" class="option-icon" mode="aspectFill" /> <text>从相册选择</text> </view> </view> </view> <view v-else-if="modalType === 'nickname'"> <input type="text" class="input" placeholder="请输入昵称" v-model="editValue" /> </view> <view v-else-if="modalType === 'gender'"> <view class="gender-options"> <view class="option" :class="{ active: editValue === '男' }" @click="editValue = '男'"> 男 </view> <view class="option" :class="{ active: editValue === '女' }" @click="editValue = '女'"> 女 </view> <view class="option" :class="{ active: editValue === '保密' }" @click="editValue = '保密'"> 保密 </view> </view> </view> <view v-else-if="modalType === 'age'"> <input type="number" class="input" placeholder="请输入年龄" v-model="editValue" /> </view> </view> <view class="modal-footer"> <button class="cancel-btn" @click="closeModal">取消</button> <button class="confirm-btn" @click="confirmEdit">确定</button> </view> </view> </view> </view> </template> <script> export default { data() { return { userInfo: { avatar: '/static/user.jpg', nickname: uni.getStorageSync('currentUser') || '', gender: '', age: '' }, showModal: false, modalType: '', modalTitle: '', editValue: '' } }, onShow() { this.loadUserInfo(); }, methods: { loadUserInfo() { const savedInfo = uni.getStorageSync('userInfo') || {}; this.userInfo = { ...this.userInfo, ...savedInfo }; console.log('加载的用户信息:', this.userInfo); }, editAvatar() { this.modalType = 'avatar'; this.modalTitle = '更换头像'; this.showModal = true; }, // 优化后的chooseAvatar方法(核心修改) async chooseAvatar(type) { // 显示加载提示,提升用户体验 uni.showLoading({ title: '处理中...' }); try { // 1. 选择图片(Promise封装,便于async/await) const chooseRes = await new Promise((resolve, reject) => { uni.chooseImage({ count: 1, sourceType: type === 'camera' ? ['camera'] : ['album'], sizeType: ['compressed'], // 优先压缩,减少文件大小 success: resolve, fail: (err) => reject(new Error(`选择图片失败: ${err.errMsg}`)) }); }); // 2. 准备文件系统和路径 const fs = wx.getFileSystemManager(); const timestamp = Date.now(); // 时间戳确保文件名唯一 const fileName = `avatar_${timestamp}.png`; const savedPath = `${wx.env.USER_DATA_PATH}/${fileName}`; // 固定存储目录 // 3. 保存文件为永久路径 await new Promise((resolve, reject) => { fs.saveFile({ tempFilePath: chooseRes.tempFilePaths[0], filePath: savedPath, success: (res) => { console.log('[user-center] 图片保存成功,路径:', res.savedFilePath); resolve(res.savedFilePath); }, fail: (err) => reject(new Error(`保存图片失败: ${err.errMsg}`)) }); }); // 4. 更新用户信息并同步存储 const userInfo = { ...uni.getStorageSync('userInfo') || {} }; // 深拷贝避免引用问题 userInfo.avatar = savedPath; uni.setStorageSync('userInfo', userInfo); console.log('[user-center] 本地存储已更新:', userInfo.avatar); // 5. 实时更新视图并通知其他组件 this.userInfo.avatar = savedPath; // 更新当前组件 uni.$emit('avatarUpdated', savedPath); // 通知my-title组件 console.log('[user-center] 已发送全局更新事件'); // 6. 关闭弹窗和加载提示 this.closeModal(); uni.hideLoading(); uni.showToast({ title: '头像更新成功', icon: 'success' }); } catch (err) { // 统一错误处理 console.error('[user-center] 头像处理异常:', err); uni.hideLoading(); // 确保加载提示关闭 uni.showToast({ title: err.message || '更新失败,请重试', icon: 'none', duration: 2000 }); } }, editNickname() { this.modalType = 'nickname'; this.modalTitle = '修改昵称'; this.editValue = this.userInfo.nickname || ''; this.showModal = true; }, editGender() { this.modalType = 'gender'; this.modalTitle = '修改性别'; this.editValue = this.userInfo.gender || '保密'; this.showModal = true; }, editAge() { this.modalType = 'age'; this.modalTitle = '修改年龄'; this.editValue = this.userInfo.age || ''; this.showModal = true; }, confirmEdit() { if (this.modalType === 'nickname') { this.userInfo.nickname = this.editValue; } else if (this.modalType === 'gender') { this.userInfo.gender = this.editValue; } else if (this.modalType === 'age') { this.userInfo.age = this.editValue; } this.saveUserInfo(); this.closeModal(); uni.showToast({ title: '修改成功', icon: 'success' }); }, closeModal() { this.showModal = false; this.editValue = ''; }, saveUserInfo() { uni.setStorageSync('userInfo', this.userInfo); }, logout() { uni.showModal({ title: '确认退出', content: '确定要退出当前账号吗?', success: (res) => { if (res.confirm) { uni.removeStorageSync('isLoggedIn'); uni.removeStorageSync('currentUser'); uni.removeStorageSync('userInfo'); uni.navigateTo({ url: '/pages/login/login' }); } } }); } } } </script> <style lang="scss"> .user-center { background-color: #f5f5f5; min-height: 100vh; .header { height: 100rpx; background-color: #fff; display: flex; align-items: center; justify-content: center; border-bottom: 1rpx solid #eee; .title { font-size: 36rpx; font-weight: bold; color: #333; } } .info-card { background-color: #fff; margin-top: 20rpx; padding: 0 30rpx; .info-item { display: flex; align-items: center; height: 100rpx; border-bottom: 1rpx solid #eee; .label { font-size: 32rpx; color: #333; width: 140rpx; } .content { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 20rpx; .avatar { width: 80rpx; height: 80rpx; border-radius: 50%; } text { font-size: 30rpx; color: #666; } } .arrow { font-size: 30rpx; color: #999; margin-left: 10rpx; } } } .logout-btn { margin: 60rpx 30rpx; height: 90rpx; background-color: #ff4d4f; color: #fff; font-size: 34rpx; border-radius: 10rpx; display: flex; align-items: center; justify-content: center; } .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; .modal-content { background-color: #fff; width: 600rpx; border-radius: 20rpx; .modal-header { height: 100rpx; display: flex; align-items: center; justify-content: space-between; padding: 0 30rpx; border-bottom: 1rpx solid #eee; .modal-title { font-size: 34rpx; font-weight: bold; color: #333; } .close { font-size: 40rpx; color: #999; } } .modal-body { padding: 30rpx; .avatar-options { display: flex; justify-content: space-around; margin-top: 40rpx; .option { display: flex; flex-direction: column; align-items: center; .option-icon { width: 120rpx; height: 120rpx; border-radius: 10rpx; margin-bottom: 20rpx; } } } .gender-options { display: flex; justify-content: space-around; margin-top: 20rpx; .option { width: 160rpx; height: 80rpx; border: 1rpx solid #ddd; border-radius: 10rpx; display: flex; align-items: center; justify-content: center; font-size: 32rpx; &.active { border-color: #007aff; color: #007aff; } } } .input { width: 100%; height: 80rpx; border: 1rpx solid #ddd; border-radius: 10rpx; padding: 0 20rpx; font-size: 32rpx; } } .modal-footer { display: flex; height: 100rpx; border-top: 1rpx solid #eee; .cancel-btn, .confirm-btn { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 34rpx; } .confirm-btn { color: #007aff; font-weight: bold; } } } } } </style> <template> <view class="my-title"> <!-- Logo --> <navigator class="logo" url="/pages/index/index"> <image class="logo-img" src="/static/logo.png" mode="aspectFill" /> </navigator> <!-- 搜索框 --> <view class="search-icon"> <image src="/static/search.jpg" mode="aspectFill" /> </view> <!-- 用户头像 --> <view class="user-icon"> <image :src="userAvatar" mode="aspectFill" @error="handleImgError" @load="handleImgLoad" :key="avatarKey" /> </view> <!-- 下载APP按钮 --> <view class="down-app"> 下载APP </view> </view> </template> <script> export default { name: "MyTitle", data() { return { userAvatar: '/static/user.jpg', avatarKey: 0, syncTimer: null }; }, // 页面显示时强制刷新(解决切页后不同步问题) onShow() { console.log('[my-title] 页面显示,强制加载最新头像'); this.loadAvatar(); }, onLoad() { console.log('[my-title] 初始化,开始监听事件'); // 监听全局事件(确保任何页面修改都能触发) uni.$on('avatarUpdated', (newPath) => { console.log('[my-title] 全局事件触发,新路径:', newPath); this.updateAvatar(newPath); }); // 定时同步(3秒一次,平衡性能和可靠性) this.syncTimer = setInterval(() => { console.log('[my-title] 定时同步触发'); this.loadAvatar(); }, 3000); }, onUnload() { console.log('[my-title] 页面卸载,清理资源'); uni.$off('avatarUpdated'); clearInterval(this.syncTimer); }, methods: { // 更新头像(极简逻辑,减少拦截) updateAvatar(newPath) { if (!newPath) { console.error('[my-title] 路径为空,跳过更新'); return; } // 直接更新,不做过度验证(信任用户中心传递的路径) this.userAvatar = newPath; this.avatarKey++; // 强制重新渲染 console.log('[my-title] 头像已更新为:', newPath); }, // 从存储加载(核心:确保读取最新数据) loadAvatar() { try { const userInfo = uni.getStorageSync('userInfo') || {}; const storedPath = userInfo.avatar || '/static/user.jpg'; console.log('[my-title] 从存储读取到路径:', storedPath); // 只要路径不同就更新 if (storedPath !== this.userAvatar) { this.updateAvatar(storedPath); } } catch (e) { console.error('[my-title] 读取存储失败:', e); } }, // 加载成功回调 handleImgLoad() { console.log('[my-title] 头像加载成功,当前路径:', this.userAvatar); }, // 加载失败处理(增强重试) handleImgError(e) { console.error('[my-title] 头像加载失败,错误:', e.errMsg); console.error('[my-title] 失败路径:', this.userAvatar); // 重试存储中的最新路径 setTimeout(() => { console.log('[my-title] 失败后重试加载...'); this.loadAvatar(); }, 1000); } } } </script> <style scoped> /* 样式保持不变 */ .my-title{ display: flex; align-items: center; padding: 10rpx 20rpx; background-color: #fff; height: 100rpx; } .logo { flex: 2; display: flex; align-items: center; } .logo-img { width: 180rpx; height: 60rpx; } .search-icon { flex: 3; display: flex; justify-content: center; align-items: center; } .search-icon image { width: 60rpx; height: 44rpx; } .user-icon { flex: 1; display: flex; justify-content: center; align-items: center; } .user-icon image { width: 60rpx; height: 60rpx; border-radius: 50%; border: 1rpx solid #eee; } .down-app { flex: 2; font-size: 30rpx; background-color: #87CEEB; color: #fff; border-radius: 10rpx; padding: 10rpx 20rpx; margin-left: 10rpx; display: flex; align-items: center; justify-content: center; } </style>如何修改头像后用户头像也会发生改变
最新发布
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dituirenwu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值