基于vue-cli脚手架构建的项目,可通过npm run build把项目打包为静态文件。
打包后serve -s dist却发现页面与之前开发时的样式不同。
通过谷歌console调试,发现是组件内部的样式没有生效:
</template>
<style>
.active i,
.active label {
color: #f60;
}
.iconfont {
background: none;
padding-left: 10px;
padding-top: 6px;
font-size: 30px;
margin: 0px;
height: 30px;
width: 70px;
}
.text-nav {
font-size: 5px;
padding-bottom: 0px;
margin-bottom: 0px;
}
</style>
此时,在组件的style 标签内加上scoped 再打包,发现与开发时样式一致。
<style scoped>