久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      在VUE style中使用data中的變量的方法詳解

      在VUE style中使用data中的變量的方法詳解

      最近項(xiàng)目中的公共組件,在復(fù)用的時(shí)候,針對(duì)不同的場(chǎng)景,需要不斷變更CSS里樣式的值,而且已經(jīng)有了全局的公共組件樣式了

      如果用vue傳統(tǒng)的動(dòng)態(tài)綁定class和style的方式去修改樣式(文末會(huì)提到),需要額外寫很多變量和模塊class,那如果我的樣式的值,可以從父組件,傳到子組件,子組件根據(jù)傳入值去渲染對(duì)應(yīng)樣式的值,其實(shí)就是要再style中使用data和props中的變量,這要怎么做呢?

      相關(guān)學(xué)習(xí)推薦:javascript視頻教程

      其實(shí)很簡(jiǎn)單,只需要三步,大家來看:

      1、HTML結(jié)構(gòu)

      <Upload     ref="upload"     :show-upload-list="false"     :before-upload="handleBeforeUpload"     :disabled="disabled"     :max-size="maxSize"     action >

      2、作用區(qū)域范圍內(nèi)設(shè)置“CSS變量”

      <style lang="less" scoped> .info-img-wrap {   --textAlignPosition: center;   /deep/ .ivu-upload {    text-align: var(--textAlignPosition);   }  } <style/>

      3、在JS中通過setProperty()方法修改“–textAlignPosition”的值,從而間接改變對(duì)應(yīng)子元素的(text-align)文本對(duì)齊方式

      mounted() {     this.$nextTick(function () {      this.$refs.upload.$el.style.setProperty(       '--textAlignPosition',       this.textAlign      );     });  }

      這要就完成了。

      下面再?gòu)?fù)習(xí)一下vue中修改樣式還有另外兩種方法,1是動(dòng)態(tài)修改class,2是動(dòng)態(tài)修改style

      1、vue中可以通過對(duì)象語法和數(shù)組語法來修改class

      對(duì)象語法

      html

      <p v-bind:class="{ 'active': isActive, 'text-danger': hasError }"></p>

      js

      data: {   isActive: false,   hasError: true  }

      數(shù)組語法

      html

      <p v-bind:class="[isActive ? activeClass : '', errorClass]"></p>

      js

      data: {   isActive: false,   hasError: true,   activeClass: 'active',   errorClass: 'text-danger' }

      只需要?jiǎng)討B(tài)改變isActive和hasError的值,就可以實(shí)現(xiàn)p的綁定不同的class和去掉綁定

      2、vue中可以通過對(duì)象語法和數(shù)組語法來修改style

      對(duì)象語法

      html

      <p v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></p>

      js

      data: {   activeColor: 'red',   fontSize: 30  }

      數(shù)組語法

      html

      <p v-bind:style="[styleColor, styleSize]"></p>

      js

      data: {   styleColor: {     color: 'red'    },   styleSize:{     fontSize:'23px'   }  }

      只要改變data中的變量styleColor和styleSize,就可以動(dòng)態(tài)修改p的style了。

      相關(guān)學(xué)習(xí)推薦:編程視頻

      贊(0)
      分享到: 更多 (0)
      ?
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)