<template>
<div
:style="{ 'background-image': 'url(' + bgimg + ')' }"
class="page"
>
页面
</div>
</template>
<script>
export default {
data() {
return {
bgimg:'@img/bg.png'
bgimgArr:[
' @img/bg1.png',
'@img/bg2.png',
'@img/bg3.png',
'@img/bg4.png',
'@img/bg5.png'
]
};
},
mounted() {
this.bgimg =this.bgimgArr[Math.floor(Math.random() * this.bgimgArr.length)];
},
};
</script>
<style lang="scss" scoped>
.page {
height: 100vh;
background-size: cover;
background-repeat: no-repeat;
padding-top: 48px;
}
</style>
js随机生成背景
于 2023-12-29 18:04:51 首次发布