Browse Source

增加指令resolveImg;增加img-lazy组件以解决v-lazy指令不能使用filters的问题

master
unknown 4 years ago
parent
commit
70c45f8e82
6 changed files with 27 additions and 5 deletions
  1. +10
    -0
      src/components/img-lazy/index.vue
  2. +0
    -3
      src/filters/resolveAvator.js
  3. +8
    -0
      src/filters/resolveImg.js
  4. +4
    -1
      src/main.js
  5. +4
    -0
      src/views/demo/index.vue
  6. +1
    -1
      src/views/main_web/index/index.vue

+ 10
- 0
src/components/img-lazy/index.vue View File

@@ -0,0 +1,10 @@
<template>
<img v-lazy="src" />
</template>
<script>
export default {
props: {
src: String
}
}
</script>

+ 0
- 3
src/filters/resolveAvator.js View File

@@ -1,3 +0,0 @@
import { getFileUrl } from '@/services/oss';

export default imgSrc => getFileUrl(imgSrc) || '/static/img/avator_default.svg';

+ 8
- 0
src/filters/resolveImg.js View File

@@ -0,0 +1,8 @@
import { getFileUrl } from '@/services/oss';

export const resolveAvator = imgSrc => getFileUrl(imgSrc) || '/static/img/avator_default.svg';

export default (imgSrc, imgType) => {
const defaultImg = imgType === 'avator' ? '/static/img/avator_default.svg' : ''
return getFileUrl(imgSrc) || defaultImg;
};

+ 4
- 1
src/main.js View File

@@ -10,9 +10,10 @@ import 'element-ui/lib/theme-chalk/index.css';
import store from './store'; import store from './store';
import vuex from 'vuex'; import vuex from 'vuex';
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import resolveAvator from '@/filters/resolveAvator';
import resolveImg ,{ resolveAvator } from '@/filters/resolveImg';
import VueLazyload from 'vue-lazyload' import VueLazyload from 'vue-lazyload'
import VueContextMenu from '@xunlei/vue-context-menu' import VueContextMenu from '@xunlei/vue-context-menu'
import LazyImg from '@/components/img-lazy';


// 加载其他css // 加载其他css
import "@/../public/static/css/element_chanage.css" import "@/../public/static/css/element_chanage.css"
@@ -29,12 +30,14 @@ Vue.use(ElementUI);
Vue.use(VueLazyload); Vue.use(VueLazyload);
Vue.use(vuex); Vue.use(vuex);
Vue.prototype.$cookie = Cookies; Vue.prototype.$cookie = Cookies;
Vue.component('ImgLazy', LazyImg);


// todo DEPRECATED // todo DEPRECATED
Vue.prototype.$axios = axios; Vue.prototype.$axios = axios;
// todo DEPRECATED // todo DEPRECATED
Vue.prototype.$fetch = axios; Vue.prototype.$fetch = axios;
Vue.prototype.$fetchApi = fetchApi; Vue.prototype.$fetchApi = fetchApi;
Vue.filter('resolveImg', resolveImg);
Vue.filter('resolveAvator', resolveAvator); Vue.filter('resolveAvator', resolveAvator);


//右键菜单 //右键菜单


+ 4
- 0
src/views/demo/index.vue View File

@@ -25,6 +25,10 @@
<app-nav :list="navList" /> <app-nav :list="navList" />
</template> </template>
</app-header> </app-header>
<div style="height: 2000px" />
<img-lazy :src="'oss://1603443894479/bz.jpg' | resolveAvator" />
<img v-lazy="'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603457396447&di=9046aaf5b7fc79ce05e28cb76f289862&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F14%2F75%2F01300000164186121366756803686.jpg'" />
<img :src="'oss://1603443882955/9.jpg' | resolveAvator" />
</div> </div>
</template> </template>




+ 1
- 1
src/views/main_web/index/index.vue View File

@@ -84,7 +84,7 @@
<img <img
class="fandatupian" class="fandatupian"
@click="goFilePage(projItem)" @click="goFilePage(projItem)"
v-lazy="projItem.showImgUrl | resolveAvator"
:src="projItem.ShowImgUrl | resolveImg"
alt alt
/> />
<div class="yiyun_product_item_top"> <div class="yiyun_product_item_top">


Loading…
Cancel
Save