m0_67982952 2022-03-11 21:00 采纳率: 46.7%
浏览 169
已结题

请问uni-app中的css嵌套着写会报错能调整吗?

img

img


如图,在uni-app中,我将CSS这样嵌套写,这会报错,请问该如何修改?
代码如下:

<template>
    <view class="navbar">
        <view class="navbar-fixed">
            <view :style="{height: statusBarHeight+'px' }"></view>
            <view class="navbar-content" :style="{width:navbarWidth+'px',height:navbarHeight+'px'}">
                <view class="navbar-search">
                    <view class="navbar-search_icon"></view>
                    <view class="navbar-search_text">前端</view>
                </view>
            </view>
        </view>
        <!-- 因为 navbar-fixed 固定定位,故父元素高度为0,下面元素的作用就是将父元素的高度撑起来为45px -->
        <view :style="{height:navHeight+'px'}"></view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                statusBarHeight: 20, // 状态栏高度
                navbarHeight: 45, // 导航栏内容区域高度
                navbarWidth: 375, // 导航栏内容区域宽度
                navHeight: 45 // 整个导航栏容器高度
            };
        },
        created() {
            const info = uni.getSystemInfoSync()
            this.statusBarHeight = info.statusBarHeight
 
            // 设置导航栏搜索区域的宽度
            this.navbarWidth=info.windowWidth
            // 获取胶囊的位置,并计算导航栏的高度,下面API H5、App和阿里云小程序不支持,所以需要条件编译
            // #ifndef APP-PLUS||H5||MP-ALIPAY
            let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
            this.navbarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info.statusBarHeight)
            this.navbarWidth = menuButtonInfo.left
            this.navHeight=info.statusBarHeight+this.navbarHeight
            // #endif
        }
    }
</script>
 
<style lang="scss">
    .navbar {
 
 
        .navbar-fixed {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            background-color: $mk-base-color;
 
            .navbar-content {
                display: flex;
                justify-content: center;
                align-items: center;
                box-sizing: border-box;
                padding: 0 15px;
                height: 45px;
 
                .navbar-search {
                    display: flex;
                    align-items: center;
                    width: 100%;
                    height: 30px;
                    background: #fff;
                    border-radius: 30px;
                    padding: 0 10px;
 
                    .navbar-search_icon {
                        width: 10px;
                        height: 10px;
                        border: 1px solid red;
                        margin-right: 10px;
                    }
 
                    .navbar-search_text {
                        font-size: 12px;
                        color: #999;
                    }
                }
            }
        }
    }
</style>

请赐教,不胜感激。

  • 写回答

1条回答 默认 最新

  • 你好!机器人 2022-03-11 21:26
    关注

    多了一个},删除一个

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月26日
  • 已采纳回答 3月18日
  • 创建了问题 3月11日

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)