vue-image-lazy-xg
v0.0.22
Published
图片懒加载,可使用组件查看图片,也可以使用自定义命令
Downloads
11
Maintainers
Readme
vue-image-lazy-xg
imageLazy component for Vue3
源代码
live demo is here: https://gitee.com/derekgo/tool-collection/tree/master/imageLazyLoading/vue3/pluginVersion/v1
配置
使用imageLazy组件的配置
| 字段 | 类型 | 默认值 | 描述 |
| :-------- |:---------------|:------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| src | String | "" | 图片源地址,同原生属性一致 |
| imgList | String[] | [] | 开启图片预览功能 |
| loadingColor | String | "#2dbff1" | 加载图标主题颜色 |
| errorColor | String | "888888" | 加载图标主题颜色 |
| imgStyle | String | "" | 图片样式 |
| key | String-Number | 0 | 图片索引 | 图片索引model
,deploymentId
,tokensToGenerate
(默认值:512),temperature
,topP
详情查看:https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion |
| isShowImgDialog | Boolean | true | 是否显示图片查看弹出框 | 图片索引model
,deploymentId
,tokensToGenerate
(默认值:512),temperature
,topP
详情查看:https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion |
安装
npm i vue-image-lazy-xg --save
使用
main.ts
// script
import { createApp } from 'vue';
import App from './App.vue';
import imageLazy from "vue-image-lazy-xg"
import "vue-image-lazy-xg/lib/style.css"
const app = createApp(App);
app.use(imageLazy); //全局注册
//配置可有可有无
//app.use(imageLazyLoading,{
// loadingGif:"加载的图片",
// errorImg:"错误的图片",
//})
app.mount('#app');
App.vue
第一个写法直接用自定义命令
<template>
<div class="app-container">
<img
class="img"
v-for="item in result"
:key="item.picture"
v-img-lazy="item.picture"
/>
</div>
</template>
<script setup lang="ts">
import {ref} from "vue";
const result = [
{ picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{ picture:
'1111111111111',
picList:[]
},
{ picture:
'2222222222222222',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{ picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{
picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{
picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
}]
</script>
第二个写法用组件
<template>
<div class="app-container">
<!--默认使用方法-->
<imageLazy
:isShowImgDialog="false"
v-for="(item,key) in result"
class="img"
:key="key"
:src="item.picture"
:imgList="item?.picList"
/>
<!--自定义错误图标-->
<imageLazy
v-for="(item,key) in result"
class="img"
:key="key"
:src="item.picture"
:lazy="true"
>
<template #error>
<i :style="'font-size:58px;color:red'" class="icon image-lazy-iconfont icon-tupianjiazaishibai"></i>
</template>
</imageLazy>
</div>
</template>
<script setup lang="ts">
import {ref} from "vue";
const result = [
{ picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{ picture:
'1111111111111',
picList:[]
},
{ picture:
'2222222222222222',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{ picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{
picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
},
{
picture:
'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1enjLx.img?w=1920&h=1080&q=60&m=2&f=jpg',
picList:["https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
]
}]
</script>