国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解vuejs2.0 select 動態綁定下拉框支持多選

2019-11-19 11:42:09
字體:
來源:轉載
供稿:網友

select 下拉選擇

產品類型:這一項是select 涉及到父子組件信息傳遞 下面拆開講解

父組件

 <div class="sales-board-line">    <div class="sales-board-line-left">     產品類型:    </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” 傳入子組件 在子組件 接收這個參數

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

子組件

<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 多選

產品版本:這一項是select 涉及到父子組件信息傳遞 下面拆開講解

父組件

<div class="sales-board-line">    <div class="sales-board-line-left">     產品版本:    </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 因為vuejs2.0 放棄了$.remove 方法 可以通過lodash 方法解決

以上所述是小編給大家介紹的vuejs2.0 select動態綁定下拉框詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定边县| 绥化市| 施秉县| 景洪市| 新宁县| 开江县| 宜州市| 勃利县| 陇西县| 财经| 上思县| 八宿县| 镇巴县| 阿拉善左旗| 贵阳市| 白城市| 兴隆县| 江华| 裕民县| 咸宁市| 栖霞市| 额尔古纳市| 佳木斯市| 巴青县| 定远县| 蓬安县| 河北省| 龙山县| 临沧市| 疏勒县| 武穴市| 化州市| 图木舒克市| 新竹县| 望谟县| 大洼县| 宁远县| 收藏| 珠海市| 湘阴县| 河间市|