使⽤Vue-cli中为单独页⾯设置背景图⽚铺满全屏
啥也不说了,⼤家还是直接看代码吧~
<template>
<div id="logo">
</div>
</template>
<script>
import meadiaurl from '../../api/mediaurl'
export default {
name: "logo"
</script>
<style scoped>
#logo{
background: url("../../assets/images/Login.png");
background-size: 100% 100%;
height: 100%;
}
</style>
如果像以上代码写,⾼度为100%时,会发现背景图⽚只是内容撑起来的,却不能使整个屏幕铺满背景图;
解决⽅案:
我们要让#logo脱离⽂档流,为他添加个fixed属性
#logo{
background: url("../../assets/images/Login.png");
background-size: 100% 100%;
height: 100%;
position: fixed;
width: 100%
}
补充知识:vue 实现全屏显⽰和全屏按钮svg图
1,第⼀步安装screenfull
npm install --save screenfull
2,新建screenfull.vue组件,
<template>
<div>
<svg
t="1508738709248"
class="screenfull-svg"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="/2000/svg"
p-id="2069"
xmlns:xlink="/1999/xlink"
width="32"
height="32"
@click="click">
<path
d="M333.493443 428.647617 428.322206 333.832158 262.572184 168.045297 366.707916 64.444754 64.09683 64.444754 63.853283 366.570793 167.283957 262.460644Z"          p-id="2070"/>
<path
d="M854.845439 760.133334 688.61037 593.95864 593.805144 688.764889 759.554142 854.56096 655.44604 958.161503 958.055079 958.161503 958.274066 656.035464Z"          p-id="2071"/>
<path
d="M688.535669 428.550403 854.31025 262.801405 957.935352 366.921787 957.935352 64.34754 655.809313 64.081481 759.919463 167.535691 593.70793 333.731874Z"          p-id="2072"/>
<path
d="M333.590658 594.033341 167.8171 759.804852 64.218604 655.67219 64.218604 958.270996 366.342596 958.502263 262.234493 855.071589 428.421466 688.86108Z"          p-id="2073"/>
</svg>
</div>
</template>
<script>
import screenfull from 'screenfull' //引⼊screenfull
export default {
name: 'Screenfull',
props: {
width: {
type: Number,
default: 22
},
height: {
type: Number,
default: 22
},
fill: {
type: String,
default: '#48576a'
}
},
制作svg图片
data(){
return {
isFullscreen: false  //不可少
}
},
methods: {
click(){
if(!abled){
this.$message({
message: '你的浏览器不⽀持全屏',
type: 'warning'
})
return false
}
}
}
}
</script>
<style scoped>
.screenfull-svg {
width: 20px;
height: 20px;
cursor: pointer;
fill: red;
}
</style>
3,在需要的组件引⼊该组件即可
以上这篇使⽤Vue-cli 中为单独页⾯设置背景图⽚铺满全屏就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。