uni-app编辑器 组件样式乱或无法解析样式的情况

uni-app编辑器 组件样式乱或无法解析样式的情况

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

HBuilderX类型:正式

HBuilderX版本号:4.14

手机系统:Android

手机系统版本号:Android 12

手机厂商:小米

手机机型:xiaomi

页面类型:vue

vue版本:vue3

打包方式:云端

项目创建方式:HBuilderX

示例代码:

<template>  
    <uni-popup ref="popup" type="center">  
        <view class="bg">  
            <view class="vip-card-container">  
                <view class="title">  
                    开通VIP立享无限次恢复  
                </view>  
                <view class="icon-list">  
                    <view class="item">  
                        <image src="@/static/icon_zp.png" />  
                        <view class="text">  
                            照片找回  
                        </view>  
                    </view>  
                    <view class="item">  
                        <image src="@/static/icon_sp.png" />  
                        <view class="text">  
                            视频查找  
                        </view>  
                    </view>  
                    <view class="item">  
                        <image src="@/static/icon_wd.png" />  
                        <view class="text">  
                            文件速查  
                        </view>  
                    </view>  
                </view>  
                <view class="btn" @click="jumpPage">  
                    立即开通  
                </view>  
                <image class="close" src="@/static/clos.png" @click="closeCard">  

                </image>  
            </view>  
        </view>  

    </uni-popup>  
</template>  
<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue';
import { userInfoStore } from "@/store/userInfoStore.js";
import { appInfoStore } from '@/store/appInfoStore.js'
const { proxy } = getCurrentInstance();
const userStore = userInfoStore();
const appInfo = appInfoStore()
const userRef = ref()
const emit = defineEmits(['stopScan'])
const popup = ref();

onMounted(async () => {
await userStore.updateUserInfo();
const isWhite = appInfo.getisWhite()
userRef.value = userStore.getUserInfo()

if (!userRef.value.isVip && !isWhite) {
open()
}
})

const open = () => {
popup.value.open()
}

// 跳转会员页面
const jumpPage = () => {
emit('stopScan')
proxy.$toPage('/pages/vip/vip')
// toPage('/pages/vip/vip')
}

// 关闭
const closeCard = () => {
uni.reLaunch({
url: '/pages/index/index'
})
if (userRef.value.isVip) {
popup.value.close()
} else {
uni.reLaunch({
url: '/pages/index/index'
})
}
}

</script>
<style lang="scss" scoped>
.bg {
width: 50vh;
height: 1086rpx;
background-image: url('@/static/img_light_bg.png');
background-size: 100% 100%;
background-repeat: no-repeat;
display: flex;
align-items: center;
}

.vip-card-container {
width: 586rpx;
height: 626rpx;
margin: 0rpx auto;
background-image: url('@/static/img_pop_bg.png');
background-size: 100% 100%;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;

.title {
margin-top: 120rpx;
height: 56rpx;
font-family: PingFang HK, PingFang HK;
font-weight: 500;
font-size: 40rpx;
color: #0F244D;
line-height: 56rpx;
text-align: center;
font-style: normal;
text-transform: none;
}

.icon-list {
width: 100%;
display: flex;
align-items: center;
justify-content: space-around;

.item {
width: 108rpx;
height: 160rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

image {
width: 108rpx;
height: 108rpx;
}

.text {
height: 36rpx;
font-family: PingFang HK, PingFang HK;
font-weight: 400;
font-size: 24rpx;
color: #0F244D;
line-height: 36rpx;
text-align: center;
font-style: normal;
text-transform: none;
}
}
}

.btn {
width: 458rpx;
height: 98rpx;
background: #EB5352;
border-radius: 60rpx 60rpx 60rpx 60rpx;
color: white;
text-align: center;
line-height: 98rpx;
}

.close {
width: 64rpx;
height: 64rpx;
position: absolute;
bottom: -40rpx;
left: 50%;
transform: translateX(-50%);
}
}
</style>

操作步骤:

把这些图片资源可以注释掉,然后使用新编辑器打开看看吧~ 应该可以复现

预期结果:

图片 无法上传!

实际结果:

我也无法上传图片啊!


更多关于uni-app编辑器 组件样式乱或无法解析样式的情况的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app编辑器 组件样式乱或无法解析样式的情况的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在使用 uni-app 开发时,可能会遇到组件样式混乱或无法解析样式的情况。以下是一些常见的原因和解决方法:


1. 样式作用域问题

  • 原因:uni-app 默认使用了 Vue 的样式作用域(scoped),这可能导致样式无法正确应用到子组件。
  • 解决
    • 如果需要在父组件中修改子组件的样式,可以使用 ::v-deep/deep/ 深度选择器。
    /* 父组件样式 */
    ::v-deep .child-class {
      color: red;
    }
    
    • 或者关闭 scoped,但需要注意样式污染问题。

2. 样式优先级问题

  • 原因:不同的样式规则可能会发生冲突,导致某些样式被覆盖。
  • 解决
    • 检查样式优先级,必要时使用 !important 提高优先级。
    .my-class {
      color: red !important;
    }
    
    • 确保样式规则按预期顺序加载。

3. 平台差异问题

  • 原因:不同平台(如 H5、小程序、App)对样式的支持存在差异。
  • 解决
    • 使用条件编译来区分不同平台的样式。
    /* #ifdef H5 */
    .h5-style {
      font-size: 16px;
    }
    /* #endif */
    /* #ifdef MP-WEIXIN */
    .wx-style {
      font-size: 14px;
    }
    /* #endif */
    

4. 样式未正确引入或加载

  • 原因:样式文件未正确引入或加载失败。
  • 解决
    • 确保样式文件路径正确。
    • 检查样式文件是否被正确编译和打包。
    • 如果是动态加载的样式,确保网络请求成功。

5. 组件库样式冲突

  • 原因:使用了第三方组件库(如 uView、Vant 等),可能会与自定义样式冲突。
  • 解决
    • 使用组件库提供的主题定制功能。
    • 避免直接修改组件库的样式,使用 ::v-deep 覆盖默认样式。

6. CSS 预处理器问题

  • 原因:使用了 Sass、Less 等预处理器,但语法或配置不正确。
  • 解决
    • 确保预处理器已正确安装和配置。
    • 检查预处理器语法是否正确。
    • vue.config.js 中配置预处理器。
    module.exports = {
      css: {
        loaderOptions: {
          sass: {
            additionalData: `@import "@/styles/variables.scss";`
          }
        }
      }
    }
    

7. 动态样式问题

  • 原因:动态绑定的样式未正确解析。
  • 解决
    • 确保动态绑定的样式语法正确。
    <template>
      <div :style="{ color: textColor }">动态样式</div>
    </template>
    <script>
    export default {
      data() {
        return {
          textColor: 'red'
        };
      }
    };
    </script>
回到顶部