vue为组件样式设置作用域(局部)

对于应用来说,顶级 App 组件和布局组件中的样式可以是全局的,但是其它所有组件都应该是有作用域的。scoped 特性可以使css局部作用域,不受外界影响,不止要使用 scoped 特性,使用唯一的 class 名可以帮你确保那些三方库的 CSS 不会运用在你自己的 HTML 上。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<template>
<button class="button button-close">X</button>
</template>

<!-- 使用 `scoped` 特性 -->
<style scoped>
.button {
border: none;
border-radius: 2px;
}

.button-close {
background-color: red;
}
</style>
#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×