uni-app在手机上背景图片不显示
需求:
在uniapp代码中view的背景图加载
问题:
直接使用background-image: url(../../static/icon_top_bg.png); 会导致图片不显示
代码:
<template>
<view class="index" :style="{backgroundImage:`url(${indexBackgroundImage})`,backgroundSize: 'cover'}">
<!--你的内容-->
</view>
</template>
<script>
import indexBackgroundImage from "@/static/img/account_index.jpg"
export default {
data() {
return {
indexBackgroundImage:indexBackgroundImage
}
},
methods: {
}
}
</script>
<style lang="scss" scoped="">
</style>
总结:
直接加载图片可能不会显示,绝对路径和相对路径都会不显示,需要动态加载图片地址,通过data赋值