Vue.js 極簡小例: 4 種方式樣式綁定、style 的多種方式實現

              小編:管理員 60閱讀 2022.08.19

              代碼:

              <template>
               <div id="app">
              
                  <!-- JSON方式使用樣式 -->
                  <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">樣式使用小例</div>
              
                  <!-- 原始樣式使用 -->
                  <div style="color: green; font-size: 18px;">此行樣式同于上一行</div>
              
                  <!-- 對象方式使用樣式 -->
                  <div v-bind:style="styleObject">樣式同于上2行 </div>
              
                  <!-- 數組方式使用樣式 -->
                  <div v-bind:style="[styleObject, overridingStyles]">我只是在前面基礎上把字體加粗</div>
              
                </div>
              </template>
              
              
              <script>
                export default {
                  data () {
                    return {
                      activeColor: 'green',
                      fontSize: 18,
                      styleObject: {
                        color: 'green',
                        fontSize: '18px'
                      },
                      overridingStyles: {
                        'font-weight': 'bold'
                      }
                    }
                  }
                }
              </script>
              復制

              運行效果:(紅框中)

              關聯標簽:
              秋霞久久老子无码午夜精品,欧洲av成本人在线观看免费,亚洲精品无码国模av