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

首頁(yè) > 編程 > JavaScript > 正文

Vue2.x通用條件搜索組件的封裝及應(yīng)用詳解

2019-11-19 11:26:50
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了Vue2.x通用條件搜索組件的封裝及應(yīng)用,供大家參考,具體內(nèi)容如下

效果

 

組件源碼

<template> <div class="search"> <el-select v-model="type" @change="changeType" class="select">  <el-option  v-for="item in selectItems"  :key="item.value"  :lable="item.label"  :value="item.value">  </el-option> </el-select> <div class='search-input'>  <el-input :placeholder="placeholderDes" v-model="searchValue"></el-input> </div> <el-button icon="el-icon-search" @click="search"></el-button> </div></template><script>export default { data () { return {  searchValue: '',  type: '' } }, created () { this.type = this.initType }, props: { selectItems: {  type: Array,  require: true }, placeholderDes: {  type: String,  require: true }, initType: {  type: String,  require: true } }, methods: { changeType (newType) {  this.$emit('changeType', newType) }, search () {  this.$emit('searchOk', this.searchValue) } }}</script><style lang="less" scoped>.search { display: flex; .el-select { width: 90px; height: 40px; box-sizing: border-box; border-right: none; border-radius: 0; background-color: #DDF0FE; border: 1px solid #40b0ff; } .search-input { width: 216px; height: 40px; border: 1px solid #40b0ff; border-left: none; box-sizing: border-box; font-family: 'MicrosoftYaHei'; font-size: 14px; color: #909399; border-radius: 0; } .el-button { width: 44px; height: 40px; padding: 0; border: 1px solid #40b0ff; border-radius: 0; color: #fff; background: #40b0ff; &:hover {  background: #10b0ff } }}</style>

父組件中的引用

<template> <div class="test"> <v-search :initType="initType" :selectItems="selectItems" :placeholderDes="placeholderDes" @changeType="changeType" @searchOk="searchOk"></v-search> </div></template><script>import VSearch from '@/components/Common/ZLGComponents/XGQTest/Search/Search'export default { data () { return {  selectItems: [],  selectStatus: 'devname',  initType: '',  placeholderDes: '請(qǐng)輸入要搜索的測(cè)試名稱' } }, created () { this.setSelectItems() this.setInitType() }, methods: { setSelectItems () {  this.selectItems = [{  value: '測(cè)試名',  label: '測(cè)試名'  }, {  value: '測(cè)試ID',  label: '測(cè)試ID'  }] }, changeType (newType) {  if (newType === '測(cè)試名') {  this.placeholderDes = '請(qǐng)輸入要搜索的測(cè)試名稱'  this.selectStatus = 'name'  } else if (newType === '測(cè)試ID') {  this.placeholderDes = '請(qǐng)輸入要搜索的測(cè)試ID'  this.selectStatus = 'id'  } }, searchOk (value) {  console.log(this.selectStatus)  console.log(value)  // 調(diào)用你的搜索接口,搜索條件為搜索的類型 + 搜索值  // yourSearch (this.selectStatus, value) }, setInitType () {  this.initType = '測(cè)試名' } }, components: { VSearch }}</script><style lang="less" scoped></style>

組件基于element-UI的二次封裝,適合用于使用element的項(xiàng)目,子組件父組件demo完整源碼如上所示,有疑問(wèn)建議研究一下源碼,也歡迎留言交流。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长治县| 陇南市| 札达县| 突泉县| 西充县| 哈尔滨市| 隆回县| 馆陶县| 准格尔旗| 遵化市| 栾川县| 蕉岭县| 南澳县| 江山市| 杭锦旗| 景洪市| 丰城市| 丰原市| 安化县| 长宁区| 四会市| 云林县| 疏附县| 察雅县| 辛集市| 泊头市| 双城市| 嫩江县| 嘉鱼县| 五大连池市| 武功县| 西充县| 长沙县| 天津市| 奉节县| 泽州县| 肇州县| 孝昌县| 宿州市| 昭平县| 哈尔滨市|