Vue里給v-html元素添加樣式


在Vue組件中,我們可以使用<style scoped>標簽來添加針對該組件的CSS樣式。

<template>
<div class="foo">
<div v-html="myHtml"></div>
</div>
</template>
<style scoped>
.foo { height: 300px; }
</style>
1
2
3
4
5
6
7
8
而如果在組件中使用了v-html,要為myHtml中的標簽添加CSS樣式,我們需要在寫樣式的時候添加>>>:

.foo >>> img { max-width: 100%; }
1
這樣,編譯時以上CSS才會被編譯為

.foo[data-v-xxxxxxx] img { max-width: 100%; }
---------------------
作者:岳小哥
來源:CSDN
原文:https://blog.csdn.net/yanby921005/article/details/79963722
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM