全局 CSS
想在具有 CSS 作用域的 Vue 单文件组件设置全局 CSS 样式, 该怎么设置呢 ? 让我们开始吧 👇:
vue
<template>
<p>Hello Vue.js</p>
</template>
<style scoped>
p {
font-size: 20px;
color: red;
text-align: center;
line-height: 50px;
}
/* 使其工作 */
body {
width: 100vw;
height: 100vh;
background-color: burlywood;
}
</style>
解答
vue
<template>
<p>Hello Vue.js</p>
</template>
<style scoped>
p {
font-size: 20px;
color: red;
text-align: center;
line-height: 50px;
}
/* Make it work */
:global(body) {
width: 100vw;
height: 100vh;
background-color: burlywood;
}
</style>