欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 組件中添加樣式不生效的解決方法

 更新時間:2018年07月06日 09:54:27   作者:小魚er  
這篇文章主要介紹了vue 組件中添加樣式不生效的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如何產(chǎn)生

在開發(fā)項目中遇到在組件中添加樣式不生效的情況。具體場景如下

//// vue 組件
<template>
  <div class="box" data-v-33f8ed40></div>
<template>

//我用js在上面div標簽中插入一個<p class='text'>text goes here</p>

<script>
  export default {
  ...
  mounted(){
  $('.box').html('<p class="text">text goes here</p>')
   },
  ...
  }
</script>
//style , vue組件scoped樣式都會在選擇器的最后加上data-v-***屬性
<style scoped> 
  //樣式添加了scoped
  
  .box{
  color:red;
  }
  .text{
  color:blue;
  }
</style>

瀏覽器渲染的html 和 style 如下:

//html
<div class="box" data-v-33f8ed40>
  <p class='text'>text goes here</p>
</div>

//style
.box[data-v-33f8ed40]{
color:red;
}

.text[data-v-33f8ed40]{ //樣式不生效,因為p標簽里沒有屬性data-v-33f8ed40
color:blue;
}

如何解決

很簡單將去掉 style 的 scoped 屬性。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論