您现在的位置:首页 >> 前端 >> 内容

Vuejs使用scopedstyle为v-html中标签添加CSS样式的方法

时间:2018/2/7 15:00:16 点击:

  核心提示:在Vue组件中,我们可以使用style scoped标签来添加针对该组件的CSS样式。templatep class=foop v-html=myHtml/p/p/templatestyle scop...

在Vue组件中,我们可以使用<style scoped>标签来添加针对该组件的CSS样式。

<template>
    <p class="foo">
        <p v-html="myHtml"></p>
    </p>
</template>
<style scoped>
    .foo { height: 300px; }
</style>

而如果在组件中使用了v-html,要为myHtml中的标签添加CSS样式,我们需要在写样式的时候添加>>>:

.foo >>> img { max-width: 100%; }

这样,编译时以上CSS才会被编译为

.foo[data-v-xxxxxxx] img { max-width: 100%; }

Tags:VU UE EJ JS 
作者:网络 来源:In the Clo