使用 vue 3,我只需要在訪問登錄頁面時更改正文背景顏色。
我的 index.html 是:
<body >
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
如何從組件或 vue 路由器更改正文背景顏色?
uj5u.com熱心網友回復:
在 App 組件中,如果路由與您想要的路由匹配,您可以在頂級元素上放置一個條件類。只要您的頂級元素是身體的全高和全寬。
<template>
<div class="background" :class="{ otherColor: isSignIn }">
<div id="app"></div>
</div>
</template>
<script>
export default {
computed: {
isSignIn() {
return this.$route.path === '/signIn';
}
}
}
</script>
<style>
.background {
height: 100vh;
width: 100vw;
background-color: #ffffff;
}
.otherColor {
background-color: #d4d4d4; // whatever background color you want.
}
</style>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/457851.html
