最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解vuejs2.0 select 動態(tài)綁定下拉框支持多選

 更新時(shí)間:2019年04月25日 14:35:42   作者:kingrome2017  
這篇文章主要介紹了vuejs2.0 select動態(tài)綁定下拉框 ,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

select 下拉選擇

產(chǎn)品類型:這一項(xiàng)是select 涉及到父子組件信息傳遞 下面拆開講解

父組件

 <div class="sales-board-line">
    <div class="sales-board-line-left">
     產(chǎn)品類型:
    </div>
    <div class="sales-board-line-right">
     <v-selection :selections="buyTypes" @on-change="onParamChange('buyType', $event)"></v-selection>
    </div>
   </div>
<script>
import VSelection from '../../components/base/selection'
import _ from 'lodash'
export default {
 components: {
 VSelection,
 VCounter,
 VChooser,
 VMulChooser,
 MyDialog: Dialog,
 BankChooser,
 CheckOrder
 },
 data () {
 return {
  buyNum: 0,
  buyType: {},
  versions: [],
  period: {},
  price: 0,
  versionList: [
  {
   label: '客戶版',
   value: 0
  },
  {
   label: '代理商版',
   value: 1
  },
  {
   label: '專家版',
   value: 2
  }
  ],
  periodList: [
  {
   label: '半年',
   value: 0
  },
  {
   label: '一年',
   value: 1
  },
  {
   label: '三年',
   value: 2
  }
  ],
  buyTypes: [
  {
   label: '入門版',
   value: 0
  },
  {
   label: '中級版',
   value: 1
  },
  {
   label: '高級版',
   value: 2
  }
  ],
  isShowPayDialog: false,
  bankId: null,
  orderId: null,
  isShowCheckOrder: false,
  isShowErrDialog: false
 }
 },
 methods: {
 onParamChange (attr, val) {
  this[attr] = val
  // this.getPrice()
  console.log(this[attr], attr)
 },
 getPrice () {
  let buyVersionsArray = _.map(this.versions, (item) => {
  return item.value
  })
  let reqParams = {
  buyNumber: this.buyNum,
  buyType: this.buyType.value,
  period: this.period.value,
  version: buyVersionsArray.join(',')
  }
  this.$http.post('/api/getPrice', reqParams)
  .then((res) => {
  this.price = res.data.amount
  })
 },

 onChangeBanks (bankObj) {
  this.bankId = bankObj.id
 },
 confirmBuy () {
  let buyVersionsArray = _.map(this.versions, (item) => {
  return item.value
  })
  let reqParams = {
  buyNumber: this.buyNum,
  buyType: this.buyType.value,
  period: this.period.value,
  version: buyVersionsArray.join(','),
  bankId: this.bankId
  }
  this.$http.post('/api/createOrder', reqParams)
  .then((res) => {
  this.orderId = res.data.orderId
  this.isShowCheckOrder = true
  this.isShowPayDialog = false
  }, (err) => {
  this.isShowBuyDialog = false
  this.isShowErrDialog = true
  })
 }
 },
 mounted () {
 this.buyNum = 1
 this.buyType = this.buyTypes[0]
 this.versions = [this.versionList[0]]
 this.period = this.periodList[0]
 }
}
</script>

:selections=”buyTypes” 傳入子組件 在子組件 接收這個(gè)參數(shù)

@on-change=”onParamChange(‘buyType', $event)” 通過這個(gè)事件 接收 子組件傳入 的參數(shù)

子組件

<template>
 <div class="selection-component">
  <div class="selection-show" @click="toggleDrop">
  <span>{{ selections[nowIndex].label }}</span>
  <div class="arrow"></div>
  </div>
  <div class="selection-list" v-if="isDrop">
  <ul>
   <li v-for="(item, index) in selections" @click="chooseSelection(index)">{{ item.label }}</li>
  </ul>
  </div>
 </div>
</template>

<script>
export default {
 props: {
 selections: {
  type: Array,
  default: [{
  label: 'test',
  value: 0
  }]
 }
 },
 data () {
 return {
  isDrop: false,
  nowIndex: 0
 }
 },
 methods: {
 toggleDrop () {
  this.isDrop = !this.isDrop
 },
 chooseSelection (index) {
  this.nowIndex = index
  this.isDrop = false
  this.$emit('on-change', this.selections[this.nowIndex])
 }
 }
}
</script>
<style scoped>
.selection-component {
 position: relative;
 display: inline-block;
}
.selection-show {
 border: 1px solid #e3e3e3;
 padding: 0 20px 0 10px;
 display: inline-block;
 position: relative;
 cursor: pointer;
 height: 25px;
 line-height: 25px;
 border-radius: 3px;
 background: #fff;
}
.selection-show .arrow {
 display: inline-block;
 border-left: 4px solid transparent;
 border-right: 4px solid transparent;
 border-top: 5px solid #e3e3e3;
 width: 0;
 height: 0;
 margin-top: -1px;
 margin-left: 6px;
 margin-right: -14px;
 vertical-align: middle;
}
.selection-list {
 display: inline-block;
 position: absolute;
 left: 0;
 top: 25px;
 width: 100%;
 background: #fff;
 border-top: 1px solid #e3e3e3;
 border-bottom: 1px solid #e3e3e3;
 z-index: 5;
}
.selection-list li {
 padding: 5px 15px 5px 10px;
 border-left: 1px solid #e3e3e3;
 border-right: 1px solid #e3e3e3;
 cursor: pointer;
 background: #fff;
 white-space: nowrap;
 overflow: hidden;
 text-overflow: ellipsis;

}
.selection-list li:hover {
 background: #e3e3e3;
}
</style>

select 多選

產(chǎn)品版本:這一項(xiàng)是select 涉及到父子組件信息傳遞 下面拆開講解

父組件

<div class="sales-board-line">
    <div class="sales-board-line-left">
     產(chǎn)品版本:
    </div>
    <div class="sales-board-line-right">
     <v-mul-chooser
     :selections="versionList"
     @on-change="onParamChange('versions', $event)"></v-mul-chooser>
    </div>
   </div>

子組件

<template>
 <div class="chooser-component">
  <ul class="chooser-list">
   <li
   v-for="(item, index) in selections"
   @click="toggleSelection(index)"
   :title="item.label"
   :class="{active: checkActive(index)}"
   >{{ item.label }}</li>
  </ul>
  </div>
 </div>
</template>

<script>
import _ from 'lodash'
export default {
 props: {
 selections: {
  type: Array,
  default: [{
  label: 'test',
  value: 0
  }]
 }
 },
 data () {
 return {
  nowIndexes: [0]
 }
 },
 methods: {
 toggleSelection (index) {
  if (this.nowIndexes.indexOf(index) === -1) {
  this.nowIndexes.push(index) 
  }
  else {
  this.nowIndexes = _.remove(this.nowIndexes, (idx) => {
   return idx !== index
  })
  }
  let nowObjArray = _.map(this.nowIndexes, (idx) => {
  return this.selections[idx]
  })
  this.$emit('on-change', nowObjArray)
 },
 checkActive (index) {
  return this.nowIndexes.indexOf(index) !== -1
 }
 }
}
</script>

<style scoped>
.chooser-component {
 position: relative;
 display: inline-block;
}
.chooser-list li{
 display: inline-block;
 border: 1px solid #e3e3e3;
 height: 25px;
 line-height: 25px;
 padding: 0 8px;
 margin-right: 5px;
 border-radius: 3px;
 text-align: center;
 cursor: pointer;
}
.chooser-list li.active {
 border-color: #4fc08d;
 background: #4fc08d;
 color: #fff;
}
</style>

這里用到 lodash 因?yàn)関uejs2.0 放棄了$.remove 方法 可以通過lodash 方法解決

以上所述是小編給大家介紹的vuejs2.0 select動態(tài)綁定下拉框詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Vue利用vue-baidu-map實(shí)現(xiàn)獲取經(jīng)緯度和搜索地址

    Vue利用vue-baidu-map實(shí)現(xiàn)獲取經(jīng)緯度和搜索地址

    在開發(fā)項(xiàng)目的時(shí)候,發(fā)現(xiàn)需要獲取經(jīng)緯度,由于這個(gè)項(xiàng)目是用vue寫的,最后決定使用vue-baidu-map來快速獲取經(jīng)緯度,感興趣的可以了解一下
    2022-09-09
  • 關(guān)于vue.js過渡css類名的理解(推薦)

    關(guān)于vue.js過渡css類名的理解(推薦)

    這篇文章主要介紹了關(guān)于vue.js過渡css類名的理解,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-04-04
  • 詳解Vue.directive 自定義指令

    詳解Vue.directive 自定義指令

    這篇文章主要介紹了Vue.directive 自定義指令,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • 詳細(xì)分析vue響應(yīng)式原理

    詳細(xì)分析vue響應(yīng)式原理

    這篇文章主要介紹了vue響應(yīng)式原理的的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • vue & vue Cli 版本及對應(yīng)關(guān)系解讀

    vue & vue Cli 版本及對應(yīng)關(guān)系解讀

    這篇文章主要介紹了vue & vue Cli 版本及對應(yīng)關(guān)系,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • 淺談vue引入css,less遇到的坑和解決方法

    淺談vue引入css,less遇到的坑和解決方法

    下面小編就為大家分享一篇淺談vue引入css,less遇到的坑和解決方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • vue中集成省市區(qū)街四級地址組件的實(shí)現(xiàn)過程

    vue中集成省市區(qū)街四級地址組件的實(shí)現(xiàn)過程

    我們在開發(fā)中常會遇到選擇地址的需求,有時(shí)候只需要選擇省就可以,有時(shí)候則需要選擇到市、縣,以至于鄉(xiāng)鎮(zhèn),甚至哪個(gè)村都有可能,下面這篇文章主要給大家介紹了關(guān)于vue中集成省市區(qū)街四級地址組件的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • VUE開發(fā)一個(gè)圖片輪播的組件示例代碼

    VUE開發(fā)一個(gè)圖片輪播的組件示例代碼

    本篇文章主要介紹了VUE開發(fā)一個(gè)圖片輪播的組件示例代碼,對圖片輪播效果感興趣的小伙伴們可以參考一下。
    2017-03-03
  • axios異步提交表單數(shù)據(jù)的幾種方法

    axios異步提交表單數(shù)據(jù)的幾種方法

    這篇文章主要給大家介紹了關(guān)于axios異步提交表單數(shù)據(jù)的幾種方法,文中通過示例代碼介紹的非常詳細(xì),對各位大家學(xué)習(xí)或者使用axios具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • vue Tab切換以及緩存頁面處理的幾種方式

    vue Tab切換以及緩存頁面處理的幾種方式

    這篇文章主要介紹了vue Tab切換以及緩存頁面處理的幾種方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評論

福建省| 台湾省| 河池市| 金昌市| 鄂托克前旗| 怀来县| 怀来县| 青铜峡市| 锡林浩特市| 扶风县| 资溪县| 绥棱县| 图片| 沛县| 海淀区| 吴忠市| 旌德县| 沙坪坝区| 永修县| 德庆县| 清水县| 探索| 晋城| 苍南县| 电白县| 文安县| 凉山| 利辛县| 明溪县| 雅安市| 收藏| 南木林县| 金秀| 滦平县| 阿拉尔市| 大城县| 府谷县| 新乡县| 忻州市| 九江市| 额尔古纳市|