欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用Vue.js實(shí)現(xiàn)求職在線之職位查詢功能

 更新時(shí)間:2017年07月03日 09:45:57   作者:明眸在心丶  
Vue.js是當(dāng)下很火的一個(gè)JavaScript MVVM庫(kù),它是以數(shù)據(jù)驅(qū)動(dòng)和組件化的思想構(gòu)建的。下面這篇文章主要給大家介紹了關(guān)于利用Vue.js實(shí)現(xiàn)求職在線之職位查詢功能的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。

前言

Vue.js是當(dāng)下很火的一個(gè)JavaScript MVVM庫(kù),它是以數(shù)據(jù)驅(qū)動(dòng)和組件化的思想構(gòu)建的。相比于Angular.js,Vue.js提供了更加簡(jiǎn)潔、更易于理解的API,使得我們能夠快速地上手并使用Vue.js。

本文主要介紹的是關(guān)于利用Vue.js實(shí)現(xiàn)職位查詢功能的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面來(lái)一起看看詳細(xì)的介紹:

知識(shí)點(diǎn):

v-on, v-for, v-if, props, $emit,動(dòng)態(tài)Prop, Class 與 Style 綁定

P1 分頁(yè)查詢

查詢參數(shù)

查詢參數(shù):公司名稱company, 職位類型type, 月薪范圍salaryMin salaryMax

說(shuō)明:通過(guò)axios.post攜帶參數(shù)發(fā)出請(qǐng)求,后端采取分頁(yè)查詢的方式向前臺(tái)返回指定條數(shù)的數(shù)據(jù)。主要利用MongoDB Limit()限制讀取的記錄條數(shù), Skip()跳過(guò)指定數(shù)量的數(shù)據(jù),數(shù)據(jù)量很小1w+。

// 分頁(yè)
exports.pageQuery = function (page, pageSize, Model, populate, queryParams, projection, sortParams, callback) {
 var start = (page - 1) * pageSize; // 根據(jù) page 和 pageSize 得到 skip 要跳過(guò)的記錄量
 var $page = {
  pageNumber: page
 };
 async.parallel({
  count: function (done) { // 查詢到總共有count條數(shù)據(jù)
   Model.count(queryParams).exec(function (err, count) {
    done(err, count);
   });
  },
  records: function (done) { // 查詢得到排序和排除字段的記錄
   Model.find(queryParams, projection).skip(start).limit(pageSize).populate(populate).sort(sortParams).exec(function (err, doc) {
    done(err, doc);
   });
  }
 }, function (err, results) {

  var list = new Array();
  for (let item of results.records) {
   list.push(item.toObject())
  }

  var count = results.count;
  $page.pageCount = parseInt((count - 1) / pageSize + 1); // 總頁(yè)數(shù)
  $page.results = list; // 單頁(yè)結(jié)果
  $page.count = count; // 總記錄量
  callback(err, $page);
 });
};

有了分頁(yè)函數(shù),查詢工作函數(shù)只要傳入?yún)?shù)即可.

關(guān)于MongoDB的模糊查詢

// 數(shù)據(jù)庫(kù)命令,就是個(gè)正則表達(dá)式: / 參數(shù) /
db.getCollection('jobs').find({company: /網(wǎng)易/})

// js里如果直接寫(xiě) /data.company/會(huì)是個(gè)字符串,Model.find({})函數(shù)識(shí)別不了,只能用 new RegExp()
company: new RegExp(data.company)
// 查詢工作
exports.findJobs = function (data, cb) {
 let searchItem = {
  company: new RegExp(data.company),
  type: new RegExp(data.type),
  money: { $gte: data.salaryMin, $lte: data.salaryMax }
 }
 for (let item in searchItem) { // 若條件為空則刪除該屬性
  if (searchItem[item] === '//') {
   delete searchItem[item]
  }
 }
 var page = data.page || 1
 this.pageQuery(page, PAGE_SIZE, Job, '', searchItem, {_id: 0, __v: 0}, {
  money: 'asc'
 }, function (error, data) {
  ...
 })
}

P2 展示查詢結(jié)果


查詢結(jié)果

數(shù)據(jù)結(jié)構(gòu)

說(shuō)明:查詢到的數(shù)據(jù)結(jié)果是對(duì)象數(shù)組,通過(guò)嵌套使用v-for輕松實(shí)現(xiàn)內(nèi)容的展示

// html
<div class="searchResult">
 <table class="table table-hover">
  <tbody class="jobList">
   <tr>
    <th v-for="item in title">{{ item }}</th>
   </tr>
   <tr v-for="(item, index) in searchResults" @click="showDesc(index)">
    <td v-for="value in item">{{ value }}</td>
   </tr>
  </tbody>
 </table>
</div>
// onSubmit()
Axios.post('http://localhost:3000/api/searchJobs', searchData)
.then(res => {
 this.searchResults = res.data.results   // 單頁(yè)查詢結(jié)果
 this.page.count = res.data.pageCount   // 總頁(yè)數(shù)
 console.log('總頁(yè)數(shù)' + this.page.count)  // 總數(shù)據(jù)量
 ...
})
.catch(err => {
 console.log(err)
})

P3 詳情卡片


詳情卡片

說(shuō)明: 通過(guò)點(diǎn)擊單行數(shù)據(jù)顯示自定義的詳情框組件DescMsg來(lái)展示具體內(nèi)容。

組成: 遮罩 + 內(nèi)容框

思路: 點(diǎn)擊父組件 SearchJob 中的單行數(shù)據(jù),通過(guò) props 向子組件 DescMsg傳遞選中行的數(shù)據(jù) jobDesc 和 showMsg: true 顯示子組件。點(diǎn)擊子組件 DescMsg 除詳情框外的其余部分,使用 $emit('hideMsg') 觸發(fā)關(guān)閉詳情頁(yè)事件,父組件在使用子組件的地方直接用 v-on 來(lái)監(jiān)聽(tīng)子組件觸發(fā)的事件,設(shè)置 showMsg: false 關(guān)閉詳情頁(yè)。

// 父組件中使用 DescMsg
<DescMsg :jobDesc="jobDesc" :showMsg="showMsg" v-on:hideMsg="hideJobDesc"></DescMsg>
// 顯示詳情框
showDesc (index) {
 let item = this.searchResults[index]
 this.jobDesc = [
  { title: '標(biāo)題', value: item.posname },
  { title: '公司', value: item.company },
  { title: '月薪', value: item.money },
  { title: '地點(diǎn)', value: item.area },
  { title: '發(fā)布時(shí)間', value: item.pubdate },
  { title: '最低學(xué)歷', value: item.edu },
  { title: '工作經(jīng)驗(yàn)', value: item.exp },
  { title: '詳情', value: item.desc },
  { title: '福利', value: item.welfare },
  { title: '職位類別', value: item.type },
  { title: '招聘人數(shù)', value: item.count }
 ]
 this.showMsg = true
},
// 關(guān)閉詳情框
hideJobDesc () {
 this.showMsg = false
}
// 子組件 DescMsg

<template>
 <div class="wrapper" v-if="showMsg">
 <div class="shade" @click="hideShade"></div>
 <div class="msgBox">
  <h4 class="msgTitle">詳情介紹</h4>
  <table class="table table-hover">
  <tbody class="jobList">
   <tr v-for="item in jobDesc" :key="item.id">
   <td class="title">{{ item.title }}</td>
   <td class="ctn">{{ item.value }}</td>
   </tr>
  </tbody>
  </table>
  <div class="ft">
  <button type="button" class="btn btn-primary" @click="fllow">關(guān)注</button>
  </div>
 </div>
 </div>
</template>

<script>

export default {
 data () {
 return {
 }
 },
 props: {
 jobDesc: {
  type: Array,
  default: []
 },
 showMsg: {
  type: Boolean,
  default: false
 }
 },
 methods: {
 hideShade () {
  this.$emit('hideMsg')
 },
 fllow () {
  alert('1')
 }
 }
}
</script>

P4 頁(yè)號(hào)


頁(yè)號(hào)

說(shuō)明: 根據(jù)查詢得到的總頁(yè)數(shù) count,規(guī)定一次最多顯示10個(gè)頁(yè)號(hào)。

思路: 通過(guò)v-for渲染頁(yè)號(hào),即v-for="(item, index) of pageList" ,并為每個(gè)li綁定Class 即 :class="{active: item.active} 。當(dāng)頁(yè)數(shù)大于10時(shí),點(diǎn)擊大于6的第n個(gè)頁(yè)號(hào)時(shí),頁(yè)數(shù)整體向右移動(dòng)1,否則整體向左移動(dòng)1。為點(diǎn)擊某一頁(yè)數(shù)后item.active = true ,該頁(yè)數(shù)添加樣式.active。

html

<!-- 底部頁(yè)號(hào)欄 -->
<div class="pageButtons">
 <nav aria-label="Page navigation">
  <ul class="pagination">
   <li :class="{disabled: minPage}">
    <a aria-label="Previous">
     <span aria-hidden="true">«</span>
    </a>
   </li>
   <li v-for="(item, index) of pageList" :class="{active: item.active}">
    <a @click="onSubmit(index)">{{ item.value }}</a>
   </li>
   <li :class="{disabled: maxPage}">
    <a aria-label="Next">
     <span aria-hidden="true">»</span>
    </a>
   </li>
  </ul>
 </nav>
</div>

js

export default {
 data () {
 return {
  page: {
  selected: 0, // 選中頁(yè)數(shù)
  count: 0,  // 總頁(yè)數(shù)
  size: 10  // 最大顯示頁(yè)數(shù)
  },
  pageList: [
  {active: false, value: 1} // 默認(rèn)包含頁(yè)數(shù)1
  ]
 }
 },
 methods: {
  // index 代表從左到開(kāi)始第index個(gè)頁(yè)號(hào),好吧我也搞混了,最多10個(gè)
 onSubmit (index) {
  if (index === -1) { // index為-1代表直接點(diǎn)擊查詢按鈕觸發(fā)的事件,初始化數(shù)據(jù)
  index = 0
  this.page.selected = 0
  this.pageList = [
   {active: false, value: 1}
  ]
  }
  Axios.post('http://localhost:3000/api/searchJobs', searchData)
  .then(res => {
  this.page.count = res.data.pageCount // 總頁(yè)數(shù)
  let pageNumber = 1 // 默認(rèn)第1頁(yè)

  // 若index >= 6且顯示的最后一個(gè)頁(yè)號(hào)小于總頁(yè)數(shù),則整體向后移動(dòng)1,選中的頁(yè)號(hào)相應(yīng)向左移動(dòng)1,即index--
  if (index >= 6 && (this.page.count - this.pageList[9].value) > 0) {
   pageNumber = this.pageList[1].value
   index--
  } else if (index < 6 && this.pageList[0].value !== 1) {
   pageNumber = this.pageList[0].value - 1
   index++
  }
  this.pageList = [] // 初始化 pageList,之后會(huì)重新渲染
  this.page.size = (this.page.count > 10) ? 10 : this.page.count
  for (let i = 0; i < this.page.size; i++) {
   let item = {
   active: false,
   value: pageNumber
   }
   pageNumber++
   this.pageList.push(item)
  }
  // 改變當(dāng)前選中頁(yè)號(hào)下標(biāo)樣式,index 代表從左到開(kāi)始第index個(gè)頁(yè)號(hào),最多10個(gè)
  this.pageList[this.page.selected].active = false
  this.pageList[index].active = true
  this.page.selected = index
  console.log(searchData.page)
  })
  .catch(err => {
  console.log(err)
  })
 }
 }
}

源碼下載地址:Github源碼

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • 在Vue中使用scoped屬性實(shí)現(xiàn)樣式隔離的原因解析

    在Vue中使用scoped屬性實(shí)現(xiàn)樣式隔離的原因解析

    scoped是Vue的一個(gè)特殊屬性,可以應(yīng)用于<style>標(biāo)簽中的樣式,這篇文章給大家介紹在Vue中,使用scoped屬性為什么可以實(shí)現(xiàn)樣式隔離,感興趣的朋友一起看看吧
    2023-12-12
  • Vue3 組件間通信之mitt實(shí)現(xiàn)任意組件間通信的步驟

    Vue3 組件間通信之mitt實(shí)現(xiàn)任意組件間通信的步驟

    mitt 主要有4個(gè)API:emit(觸發(fā)某個(gè)事件)、on(綁定事件)、off(解綁某個(gè)事件)、all(獲取所有綁定的事件),這篇文章主要介紹了Vue3 組件間通信之mitt實(shí)現(xiàn)任意組件間通信,需要的朋友可以參考下
    2024-05-05
  • Vue全局注冊(cè)與局部注冊(cè)兩種組件注冊(cè)的方式

    Vue全局注冊(cè)與局部注冊(cè)兩種組件注冊(cè)的方式

    本文主要介紹了Vue全局注冊(cè)與局部注冊(cè)兩種組件注冊(cè)的方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • vue中利用three.js實(shí)現(xiàn)全景圖的完整示例

    vue中利用three.js實(shí)現(xiàn)全景圖的完整示例

    這篇文章主要給大家介紹了關(guān)于vue中利用three.js實(shí)現(xiàn)全景圖的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果

    Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果

    這篇文章主要為大家詳細(xì)介紹了Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • vue項(xiàng)目如何刷新當(dāng)前頁(yè)面的方法

    vue項(xiàng)目如何刷新當(dāng)前頁(yè)面的方法

    這篇文章主要介紹了vue項(xiàng)目如何刷新當(dāng)前頁(yè)面的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • vue elementUI table表格自定義樣式滾動(dòng)效果

    vue elementUI table表格自定義樣式滾動(dòng)效果

    這篇文章主要介紹了vue elementUI table表格自定義樣式滾動(dòng)效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-08-08
  • 關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié)

    關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié)

    這篇文章主要介紹了關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue項(xiàng)目中使用bpmn為節(jié)點(diǎn)添加顏色的方法

    vue項(xiàng)目中使用bpmn為節(jié)點(diǎn)添加顏色的方法

    這篇文章主要介紹了vue項(xiàng)目中使用bpmn為節(jié)點(diǎn)添加顏色的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04
  • 使用el-form之表單校驗(yàn)自動(dòng)定位到報(bào)錯(cuò)位置問(wèn)題

    使用el-form之表單校驗(yàn)自動(dòng)定位到報(bào)錯(cuò)位置問(wèn)題

    這篇文章主要介紹了使用el-form之表單校驗(yàn)自動(dòng)定位到報(bào)錯(cuò)位置問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05

最新評(píng)論