Skip to content

Commit a6fa4f6

Browse files
committed
feat: 将filter挂载到vue原型上,方便在实例中使用
1 parent 0585d31 commit a6fa4f6

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed

src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Object.keys(filters).forEach(key => {
3333
Vue.filter(key, filters[key])
3434
})
3535

36+
// 将过滤器挂载到vue原型上,方便在实例中使用
37+
Vue.prototype.Filters = filters
38+
3639
Vue.use(ElementUI)
3740
Vue.use(lazyLoad)
3841
Vue.use(VueRouter)

src/views/expert.vue

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,23 @@
11
<template>
22
<div class="expert-list-wrap">
33
<div class="technician w1190">
4-
<!--<div class="industry-tag">
5-
<span>筛选行业:</span>
6-
<a v-for="(item,index) in Items" v-on:click="tabActiveIndex = index" :class="{active: tabActiveIndex === index}">法律咨询</a>
7-
<a>其他</a>
8-
</div>-->
94

10-
<div class="technician-list fn-clear"
11-
v-for="(item,index) in technicianLists">
5+
<div class="technician-list fn-clear" v-for="(item,index) in technicianLists">
126
<div class="technician-list-l fn-left">
137
<!-- <img :src="item.imgUrl | imgCdn"> -->
14-
<img v-if="item.imgUrl"
15-
v-lazyload="lazyLoadPic(item.imgUrl)"
16-
@click="jpExpertDetail(item.id)">
17-
<img v-else
18-
src="../assets/img/head.png"
19-
@click="jpExpertDetail(item.id)">
8+
<img v-if="item.imgUrl" v-lazyload="Filters.imgCdn(item.imgUrl)" @click="jpExpertDetail(item.id)">
9+
<img v-else src="../assets/img/head.png" @click="jpExpertDetail(item.id)">
2010
</div>
2111
<div class="technican-list-r fn-left">
2212
<div class="expert-brief">
23-
<h5 @click="jpExpertDetail(item.id)"
24-
:title="item.expertName">{{item.expertName | subStr(6)}}</h5>
25-
<span class="location"
26-
:title="item.city">{{ item.city | subStr(10) }}</span>
27-
<span class="company"
28-
:title="item.positionName"
29-
v-if="item.positionName">{{item.positionName | subStr(10) }}</span><span v-if="isNotEmpty(item)"> | </span><span :title="item.companyName"
30-
v-if="item.companyName">{{item.companyName | subStr(10)}}</span>
31-
<button v-if="item.isFavorite == -1"
32-
class="collection"
33-
:plain="true"
34-
@click="handleCollection(1,item,index)">收藏专家</button>
35-
<button v-else-if="item.isFavorite == 0"
36-
class="collection"
37-
:plain="true"
38-
@click="handleCollection(1,item,index)">收藏专家</button>
39-
<button v-else
40-
class="not-collection"
41-
@click="handleCollection(0,item,index)">取消收藏</button>
13+
<h5 @click="jpExpertDetail(item.id)" :title="item.expertName">{{item.expertName | subStr(6)}}</h5>
14+
<span class="location" :title="item.city">{{ item.city | subStr(10) }}</span>
15+
<span class="company" :title="item.positionName" v-if="item.positionName">{{item.positionName | subStr(10) }}</span>
16+
<span v-if="isNotEmpty(item)"> | </span>
17+
<span :title="item.companyName" v-if="item.companyName">{{item.companyName | subStr(10)}}</span>
18+
<button v-if="item.isFavorite == -1" class="collection" :plain="true" @click="handleCollection(1,item,index)">收藏专家</button>
19+
<button v-else-if="item.isFavorite == 0" class="collection" :plain="true" @click="handleCollection(1,item,index)">收藏专家</button>
20+
<button v-else class="not-collection" @click="handleCollection(0,item,index)">取消收藏</button>
4221
</div>
4322
<div class="expert-detail">
4423
<h4>专家简介</h4>
@@ -49,19 +28,14 @@
4928

5029
<!--分页-->
5130
<div class="block">
52-
<el-pagination @current-change="handleCurrentChange"
53-
:current-page="currentPage1"
54-
layout="prev, pager, next, jumper"
55-
:page-size="8"
56-
:total="technicianListsAll.totalSize">
31+
<el-pagination @current-change="handleCurrentChange" :current-page="currentPage1" layout="prev, pager, next, jumper" :page-size="8" :total="technicianListsAll.totalSize">
5732
</el-pagination>
5833
</div>
5934
</div>
6035
</div>
6136
</template>
6237
<script>
6338
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
64-
import Vue from 'vue'
6539
6640
export default {
6741
data() {
@@ -99,11 +73,8 @@ export default {
9973
}
10074
},
10175
methods: {
102-
lazyLoadPic(url) {
103-
return Vue.filter('imgCdn')(url)
104-
},
10576
isNotEmpty(item) {
106-
if (item.positionName &&  item.companyName)  {
77+
if (item.positionName && item.companyName) {
10778
return true;
10879
}
10980
return false;

0 commit comments

Comments
 (0)