亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

如何產(chǎn)生

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

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

//我用js在上面div標(biāo)簽中插入一個(gè)<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]{ //樣式不生效,因?yàn)閜標(biāo)簽里沒有屬性data-v-33f8ed40
color:blue;
}

如何解決

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

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

相關(guān)文章

最新評論